home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d12
/
scd113.arc
/
MANUAL.DOC
< prev
next >
Wrap
Text File
|
1990-06-14
|
261KB
|
11,815 lines
SoftC Database Library
Reference Manual
Version 1.13
Manual and Software Copyright 1988, 1989, 1990
by
SoftC, Ltd.
16820 Third Street North East
Ham Lake, Minnesota 55304
Telephone (612) 434-6968 Fax (612) 780-8728
ALL RIGHTS RESERVED
This document describes version 1.13 of the SoftC Database
Library, released in February, 1990.
SoftC Database Library License Agreement
This License Agreement (Agreement) is between you (the
Customer) and SoftC, Ltd. (SoftC). The Agreement pertains
to the SoftC Database Library, including the object code
libraries, sample programs, source code (if provided), and
modifications and/or recompilations of the source code (the
Product), and the documentation.
In exchange for the non-exclusive right to use the Product,
the Customer agrees to the following terms.
OWNERSHIP AND LIMITED LICENSE: The Product is owned by SoftC
and is protected by applicable copyright laws and
international treaty provisions. The Customer is granted a
non-exclusive license to use the Product on a single
computer system (i.e., with a single CPU) or network node at
a time.
COPYING AND USE: The Customer may make backup copies of the
Product, but may install and use the Product (including
modifications and/or recompilations of the software) on only
one computer or network node at a time. This means that the
Product may be used by any number of people and may be
freely moved from one computer location to another, so long
as there is no possibility of it being used at one location
while it is being used at another.
PRODUCT CODE AND DERIVATIVE WORKS: In exchange for the
benefit from having access to the Product the Customer
agrees to protect the copyright and other proprietary rights
of SoftC. Such protection includes, but is not limited to,
a) the Customer not disclosing the code (object and/or
source) and the way it functions to any party not bound by
this Agreement, b) the Customer not allowing any party not
bound by this Agreement to copy or use the Product or
documentation in violation of this Agreement and c) the
Customer may not disclose, allow disclosure, transmit, or
allow transmission, either directly or indirectly, of the
source code to any third party without the prior written
consent of SoftC. The Customer may modify and/or re-compile
the Product source code solely for the Customer's use. Such
modified and/or re-compiled versions, regardless of the
extent of the modifications or the compiler versions,
operating systems, or computer systems used, are part of the
same Product under this Agreement and shall remain the
property of SoftC subject to the same limitations upon
transfer or use as the original Product. The Customer may
reproduce and distribute application programs created using
the Product without additional licenses or fees. Any
modification of the Product source code resulting in an
application or derivative work intended for distribution
requires prior written permission from SoftC and may require
additional terms and fees.
TRANSFER: The Customer may transfer this Agreement and
Product along with all originals, any copies, and the
documentation to another party provided that such party
agrees in writing to be legally bound by these terms. The
Customer's rights shall terminate upon transfer and the
Customer agrees to discontinue immediately the use of and
destroy any and all retained copies of the Product upon
transfer. The software source code if provided under the
license is not transferrable.
LIMITED WARRANTY: The physical diskette(s) and physical
documentation are warranted to be free of defects in
materials and workmanship for a period of sixty (60) days
from the date of original purchase. For the same period,
the software is warranted against significant errors that
make it unusable for the operating system and compiler
version originally provided by SoftC. If the Customer
notifies SoftC within this 60 day period, SoftC will replace
any defective diskette and/or documentation. SoftC will
attempt to correct or help the Customer to avoid errors in
the software with efforts that SoftC believes suitable to
the problem, or at SoftC's option, authorize a refund of the
Customer's license fee. OTHER THAN THE FOREGOING
WARRANTIES, SOFTC, LTD. MAKES NO WARRANTIES, EXPRESS OR
IMPLIED, AND SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES
OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE.
SOFTC, LTD. FURTHER RESERVES THE RIGHT TO MAKE CHANGES TO
THE SPECIFICATIONS OF THE PRODUCT WITHOUT OBLIGATION TO
NOTIFY ANY PERSON OR ORGANIZATION OF SUCH CHANGES.
LIMITATION OF LIABILITY: The Customer's sole remedies are
set forth in the warranty clause above. SoftC's liability
for damages shall not exceed SoftC's suggested retail price
for the Product. In no event will SoftC be liable for any
special, incidental or consequential damages even if SoftC
has been advised of the possibility of the same.
SUPPORT: Product support, updates, fixes, enhancements, if
and as they become available, may be offered for a separate
charge, but SoftC has no obligation to provide any such
support, updates, fixes, or enhancements to the Product.
SoftC may at its sole discretion provide or discontinue
support to specific customers on separate terms determined
solely by SoftC.
EXPORT: The Customer agrees not to allow the Product or
applications created using the Product to be sent to or used
in any other country except in compliance with applicable
U.S. laws and regulations. If the Customer needs advice on
such export laws and regulations, the Customer shall contact
the U.S. Department of Commerce, Export Division,
Washington, DC 20230, U.S.A. for clarification.
LICENSE TERMINATION: This Agreement shall terminate upon
the transfer of the Product or upon breach of any term of
this Agreement by the Customer. The Customer shall cease
use of the Product upon termination. In the event that
Customer has received source code for the Product, upon
written request by SoftC, Customer shall provide written
certification by an officer of Customer that all copies of
the source code have been returned or destroyed.
GOVERNING LAW: This Agreement shall be governed by the laws
of the State of Minnesota. If any provision of this
Agreement is found void, invalid, or unenforceable, it will
not affect the validity of the balance of the Agreement,
which shall remain valid and enforceable according to its
terms. In the event any remedy herein is determined to have
failed of its essential purpose, all limitations of
liability and exclusion of damages set forth herein shall
remain in full force and effect. This Agreement may be
modified only in writing by the Customer and an authorized
representative of SoftC. Reasonable attorneys' fees and
court costs shall be awarded to the prevailing party in any
action brought in connection with an alleged breach of the
terms of this Agreement.
U.S. GOVERNMENT RESTRICTED RIGHTS: The software and
documentation are provided with RESTRICTED RIGHTS. Use,
duplication, or disclosure by the Government is subject to
restrictions as set forth in subparagraph (c)(1)(ii) of the
Rights in Technical Data and Computer Software clause at
52.227-7013. Contractor/manufacturer is SoftC, Ltd.
ACCEPTANCE OF AGREEMENT: The licensed use of the Product is
expressly conditioned upon the Customer's acceptance of
these terms. The Customer may accept these terms only by
signing and returning the Registration Form. SoftC's
acceptance of these terms is represented by shipment of the
Product.
Table Of Contents
Chapter 1 Introduction......................................... 1
Registration................................................ 2
Shareware................................................... 2
Typographic Conventions..................................... 3
Trademarks.................................................. 3
Support and Updates......................................... 3
Chapter 2 Before You Begin..................................... 4
The READ.ME File............................................ 4
Library Files............................................... 4
Installing SoftC on Your System............................. 5
SoftC Applications.......................................... 6
Compiling with Turbo C...................................... 7
Compiling with Microsoft C.................................. 7
Recompiling the Database Libraries.......................... 8
Function Naming Conventions................................. 9
Chapter 3 A Database Tutorial................................. 10
Sequential Files........................................... 10
Random Access Files........................................ 10
Keys....................................................... 11
ISAM and B-trees........................................... 11
Basic Rules................................................ 12
Data File Functions........................................ 12
Data Record I/O............................................ 13
Data Field I/O............................................. 13
Memo File Functions........................................ 14
Index File Functions....................................... 15
Index Page Functions....................................... 16
Index Key Functions........................................ 16
Chapter 4 Clock & Calendar Functions.......................... 17
Date String to String Conversion........................... 17
Date String to Numeric Conversion.......................... 17
Date Numeric to String Conversion.......................... 17
Date String Calculations................................... 18
Date Validation and Testing................................ 18
Time String to Numeric Conversion.......................... 18
Time Numeric to String Conversion.......................... 18
Time String Calculations................................... 18
Time Validation............................................ 18
Chapter 5 Miscellaneous Functions............................. 19
Program Initialization..................................... 19
Program Termination........................................ 19
Library Version............................................ 19
Errors and Warnings........................................ 19
Chapter 6 The SoftC Database Library.......................... 21
sccday..................................................... 23
v
TABLE OF CONTENTS
sccddiff................................................... 24
sccdl2s.................................................... 26
sccdn2s.................................................... 27
sccdperm................................................... 29
sccdpermi.................................................. 31
sccds2l.................................................... 33
sccds2n.................................................... 34
sccdvalid.................................................. 36
sccdxlat................................................... 37
sccleap.................................................... 39
sccleapi................................................... 40
sccmonth................................................... 41
scctdiff................................................... 43
scctn2s.................................................... 45
sccts2n.................................................... 47
scctvalid.................................................. 49
scddclose.................................................. 50
scddcreate................................................. 52
scddcreatex................................................ 55
scddinfo................................................... 58
scddopen................................................... 60
scddopenx.................................................. 62
scddsize................................................... 65
scdfget.................................................... 66
scdfgets................................................... 68
scdfgetsx.................................................. 70
scdfgett................................................... 72
scdfgettx.................................................. 74
scdfgetx................................................... 76
scdfinfo................................................... 78
scdfnam2no................................................. 80
scdfput.................................................... 82
scdfputs................................................... 84
scdfputsx.................................................. 86
scdfputt................................................... 88
scdfputtx.................................................. 90
scdfputx................................................... 92
scdinit.................................................... 94
scdkadd.................................................... 96
scdkcur.................................................... 98
scdkdate.................................................. 100
scdkdatex................................................. 101
scdkdel................................................... 103
scdkfind.................................................. 105
scdkfirst................................................. 107
scdklast.................................................. 109
scdkmake.................................................. 111
scdkmakex................................................. 114
scdknext.................................................. 116
scdkprev.................................................. 119
scdnclose................................................. 121
vi
TABLE OF CONTENTS
scdncreate................................................ 122
scdnexpr.................................................. 124
scdninfo.................................................. 126
scdnopen.................................................. 128
scdpinfo.................................................. 130
scdpnum................................................... 131
scdrclear................................................. 133
scdrcopy.................................................. 135
scdrdel................................................... 137
scdrget................................................... 139
scdrinfo.................................................. 141
scdrput................................................... 143
scdrundel................................................. 145
scdtclose................................................. 147
scdtcreate................................................ 148
scdterm................................................... 149
scdtinfo.................................................. 150
scdtopen.................................................. 152
scdvers................................................... 154
sceclr.................................................... 155
scemsg.................................................... 157
Appendix A Result Codes and Messages......................... 158
Warning Codes and Messages................................ 158
Error Codes and Messages.................................. 159
Other Messages............................................ 164
Appendix B Address List Demo Program......................... 165
Appendix C Diskette TOC Demo Program......................... 167
Index........................................................ 168
vii
Chapter 1
Introduction
C is generally considered to be a "bare-bones" language. A
way to put some flesh on those bones is to develop
generalized functions (extensions) which may be reused in
many programs. The presence of these functions can make
programming a quick and simple task. The absence of these
language extensions can mean many hours lost "re-inventing
the wheel".
Few programmers have the time required to develop and debug
such a library of functions. This is where the SoftC
Database Library comes in. This library is a collection of
functions designed to make your applications quicker and
easier to code and test. With the library you can spend time
on your application not on developing tools.
There also is a benefit to using functions found in a
toolkit library versus using the functions found in your
compiler's library. It may seem trivial, but if you ever
decide to change compilers you will find that it will take
many hours to convert your source to match the new
compiler's syntax. Using a generic toolkit such as the SoftC
Database Library will eliminate that effort.
The SoftC Database Library adds powerful capabilities to
your function library:
-dBASEIII+ data, memo, and index file functions
-dBASEIV data file functions
-date and time manipulation and calculation
The SoftC Database Library is intended for use as a
supplement to your compiler's object libraries. It contains
seventy-three user functions. Its focus is dBASEIII+
compatible data, memo, and index file manipulation
functions. The data file functions are also compatible with
dBASEIV files. The clock/calendar functions have been added
to enhance the core dBASE routines. The library is currently
1
CHAPTER 1, INTRODUCTION
available for Turbo C 2.0 and Microsoft C 5.1. These
routines were written entirely in C.
Registration
If you find this library useful, you are encouraged to
register. Refer to ORDER.DOC for registration fees. To
register, read the license agreement, print the file
ORDER.DOC, and mail the completed form to:
SoftC, Ltd.
16820 Third Street N.E.
Ham Lake, MN 55304 USA
Shareware
This library is "shareware" (user supported software) NOT
"public domain", which means that the SoftC Database
Library (including the demonstration program - SOFTC113.EXE)
is the copyrighted property of SoftC, Ltd. Registered users
are legally bound by the terms and conditions set forth in
the license agreement. Everyone is granted the right to
make copies and to freely share the UNMODIFIED demonstration
program.
The shareware concept is an attempt to provide useful
software at low cost. The expense of offering a new product
by conventional means is quite high and thus discourages
many independent authors and small companies from developing
and promoting their ideas. Shareware is an attempt to
develop a new marketing channel where products can be
introduced at minimum cost.
Everyone will benefit if shareware works. The user benefits
by having quality products at low cost, and by being able to
test software thoroughly before purchasing it. The author
benefits by being able to enter the commercial software
market without the need of large amounts of venture capital.
But it can only work with your support. If you obtain a user
supported product from a friend or coworker, and are still
using it after a few of weeks, then it is obviously worth
something to you and you should register it.
2
CHAPTER 1, INTRODUCTION
Typographic Conventions
[] Square brackets enclose optional data.
Boldface SoftC Database Library function names (such
as scdinit) and structure names when they
appear in text (but not in program examples).
Underline indicate variable names "identifiers" which
appear in text.
Trademarks
Clipper is a registered trademark of Nantucket Software.
dBASE, dBASEIII, and dBASEIV are registered trademarks of
Ashton-Tate.
Microsoft is a registered trademark of Microsoft
Corporation.
SoftC is a trademark of SoftC, Ltd.
Turbo C is a registered trademark of Borland International.
Support and Updates
Technical advice and technical support will be offered to
registered users only. Registered users will also be
notified when updates and new products are available.
We can be contacted by:
mail SoftC, Ltd.
16820 Third Street NE
Ham Lake, MN 55304 USA
telephone (612) 434-6968
after 6pm Central Time
modem at above number (use voice first so that
we can set up the modem).
GEnie "K.SCHUMANN"
CompuServ 73667,3420.
3
Chapter 2
Before You Begin
This chapter supplies instructions for installing the
library on your hard disk and compiling the source.
The READ.ME File
For last minute update information not contained in this
documentation, and/or a brief description of what's new with
this release please read the READ.ME file.
Library Files
The SoftC Database Library is distributed in several self-
extracting archive programs. The demonstration program
(SOFTC113.EXE) contains eight (8) files (you are encouraged
to freely share this completely unmodified program with
others):
DEMO1.C DEMO2.C
LICENSE.DOC MANUAL.DOC
ORDER.DOC SC_BASE.H
SCDMC50S.LIB SCDTC20S.LIB
The source code archive (SOURCE.EXE), for users registered
at that level, contains fifty-eight (58) files:
CDAY.C CDDIFF.C
CDL2S.C CDN2S.C
CDPERM.C CDS2L.C
CDS2N.C CDVALID.C
CDXLAT.C CLEAP.C
CMONTH.C CTDIFF.C
CTN2S.C CTS2N.C
CTVALID.C DDCREATE.C
DDINFO.C DDOPEN.C
DDSIZE.C DFGET.C
DFGETT.C DFINFO.C
DFNAM2NO.C DFPUT.C
DFPUTT.C DINIT.C
4
CHAPTER 2, BEFORE YOU BEGIN
DKADD.C DKCUR.C
DKDATE.C DKDEL.C
DKFIND.C DKFIRST.C
DKLAST.C DKMAKE.C
DKNEXT.C DKPREV.C
DNCREATE.C DNEXPR.C
DNINFO.C DNOPEN.C
DPGET.C DPINFO.C
DPNUM.C DPPUT.C
DRCLEAR.C DRCOPY.C
DRDEL.C DRGET.C
DRINFO.C DRPUT.C
DRUNDEL.C DTCREATE.C
DTINFO.C DTOPEN.C
DVERS.C EMSG.C
SC_BASE.NTL SC_BASE.RSP
MSCLIB.BAT TCLIB.BAT
The Turbo C object code library archive (TCLIBS.EXE)
contains the following eight (8) files:
DEMO1.C DEMO2.C
SC_BASE.H SCDTC20S.LIB
SCDTC20M.LIB SCDTC20C.LIB
SCDTC20L.LIB SCDTC20H.LIB
The Microsoft C and Quick C object code library archive
(MSCLIBS.EXE) contains the following eight (8) files:
DEMO1.C DEMO2.C
SC_BASE.H SCDMC50S.LIB
SCDMC50M.LIB SCDMC50C.LIB
SCDMC50L.LIB SCDMC50H.LIB
Installing SoftC on Your System
The SoftC Database Library source code is compatible with
all of the compilers which we support. The object code
provided is for a specific C compiler.
Many compiler manufacturers suggest a certain directory
setup to enable the compiler to find the header, object, and
library files. Rather than trying to explain the various
manufacturers suggested directory setups, we will explain
what files are required and where they are often located.
5
CHAPTER 2, BEFORE YOU BEGIN
The library header files need to be placed where they can be
found by your compiler. In many cases this is in a special
"INCLUDE" directory. Other times they are placed where your
source code is found. We would suggest that they be placed
where the header files for your compiler are located.
Your linker will need to be able to find the SoftC object
code libraries. It is suggested that these be placed where
the run-time libraries for your compiler are found.
The name of the library defines the compiler manufacturer
and version, and the memory model for which it was compiled.
All library names begin with "SCD". The next few characters
specify the compiler manufacturer and version. The last
character defines the memory model.
For example SCDTC20S.LIB is the small memory model library
for Borland's Turbo C compiler (version 2.0x).
SoftC Applications
A typical application skeleton has the following form:
#include <sc_base.h>
/* global declarations */
void main()
{
/* local declarations */
scdinit(15);
.
.
.
/* body of application */
.
.
.
scdterm();
}
6
CHAPTER 2, BEFORE YOU BEGIN
The scdinit function must be the first function called in
your application and IT MUST BE CALLED ONLY ONCE. The last
function should be scdterm. This is not a requirement but it
is good programming practice. This function should also be
called only once. See the descriptions of these functions in
the library reference section of this manual.
Compiling with Turbo C
Turbo C provides two ways of compiling programs: the
integrated environment and the command line version. In
order to use the SoftC Database Library with the integrated
environment a project file must be created and the
appropriate library must be specified in that file:
myprog /* your program name */
scdtc20s.lib /* the desired SoftC Database library */
To use the library with the command line compiler simply
include the library name in the file name list:
tcc -ml -I<header_file_path> -L<lib_file_path> myprog
scdtc20s.lib
Compiling with Microsoft C
To use the library with Microsoft's command line compiler
simply include the library name in the file name list:
7
CHAPTER 2, BEFORE YOU BEGIN
cl /AL /Zp myprog scdmc51s.lib
Recompiling the Database Libraries
If you modify a SoftC Database Library source module, then
that module and any related modules (if any) must be
recompiled and replaced in the libraries. The library source
code is compiled just like any other program.
Turbo C command line:
tcc -c -ml -I<header_file_path> -f *.c
Microsoft C command line:
cl /AL /c /Zp /W3 *.c
Refer to your compiler documentation for instructions for
replacing modules in libraries. Batch files are included
with the source code to assist you in rebuilding the
libraries.
8
CHAPTER 2, BEFORE YOU BEGIN
Function Naming Conventions
All of the SoftC Database Library functions begin with the
letters "sc". This is to differentiate them from the
standard library functions.
"scc" clock/calendar functions
"sccd" date or calendar functions
"scct" time functions
"scd" dBASE file functions
"scdd" data file functions (open, close, etc.)
"scdf" data field functions
"scdr" data record functions (write, read, delete, etc.)
"scdn" index file functions (open, close, etc.)
"scdk" index key functions (add, delete, etc.)
"scdp" index page functions
"scdt" memo file functions (open, close, etc.)
9
Chapter 3
A Database Tutorial
Most applications need to do some file I/O operations. Your
C compiler provides you with basic functions to do general
file I/O. But many cases will arise when you need to use a
database within your application. The SoftC Database Library
provides functions to enable you to integrate your program
and dBASEIII compatible data, memo, and index files, and
dBASEIV compatible data files.
For those of you who may be unfamiliar with databases, think
of a filing cabinet filled with folders of invoices ordered
alphabetically by company name. If we wish to put this
information "on computer" we have two choices for data file
I/O: a simple sequential file, or a random access file.
Sequential Files
The concept of using a sequential file to store invoice data
by company name is very simple. Just enter the data as it's
found in the filing cabinet. To access the information just
begin reading at the start of the file and continue until
finished. As you can see the time required to find a
specific record greatly increases as more and more records
are added to the file. Also the act of adding information to
the file while trying to keep it in alphabetical order
becomes very time consuming due to the fact that many
existing records will have to be moved in order to make room
for the new record.
Random Access Files
By using random access techniques it becomes much easier to
access any particular data record. All that is required is
the desired record number and you can seek to the proper
location within the data file. But how do you know which
record number to use? And what about adding records in the
middle of the data file? dBASE uses keys and an indexed
lookup system called ISAM to solve both of these problems.
10
CHAPTER 3, A DATABASE TUTORIAL
Keys
Keys are generally comprised of one or more pieces of
information (data fields) found in a data record. In our
example the company name could be used as a key. Each key
would point to one or more records found in the data file.
When many keys are grouped together they form an index file.
dBASE uses a technique called ISAM to access the underlying
B-tree structure of its index files.
ISAM and B-trees
The relationship between a key and the data file record
number is established via a "key item". Many key items are
found on an "index page". Many index pages are combined to
form an "index file". The method used to navigate through
the index file is called "Indexed Sequential Access Method"
or ISAM. B-tree (or branch tree) is the underlying structure
used in ISAM. Searching always begins at the top of the
tree. Each key item on an index page can point to another
index page (this is where the "branching" comes into play).
If a key item does not point to another index page it is
referred to as a "terminal node". A search is ended when a
terminal node is encountered.
When a data record for a specific key needs to be accessed,
the first (top) index page is searched with the desired key
text. If not at a terminal node, a determination will be
made using the branch trees as to which index page should
next be searched. This sequence of searching and branching
is followed until a terminal node is encountered. If an
exact match is found the data record number present in that
key item can be used to access the data file.
When a key needs to be added to an index file, the above
sequence of searching and branching is again followed until
the location where the new key should be placed is found.
Because of the nature of the ISAM file it is much easier and
faster to add a key to the index page than appearances may
indicate. If an index page overflows it will be split into
two pages. Likewise if it underflows it will be joined with
another index page. This system results in a minimal amount
of file I/O.
The first question above has been obviously answered, but
what about the second? The answer lies in the fact that
because we are using an index file we no longer have to keep
11
CHAPTER 3, A DATABASE TUTORIAL
the data file in alphabetical order, all we need to do is
append records to the end of the data file and add a key to
the index file.
This ends the general discussion of databases. One note, it
is good programming practice to create keys only from data
fields found in the data record, this allows the
reconstruction of an index file should something
catastrophic happen.
Basic Rules
In order to benefit fully from the SoftC Database Library,
it is necessary to use only the functions found in the
library when performing database I/O. When standard
functions such as fprintf are used, the SoftC Database
Library file manager is bypassed. This means that it can no
longer keep track of the activities in your dBASE files
which can lead to unpredictable results.
This is not to say that you cannot use the standard C file
I/O functions found in your compiler's libraries, but their
use should be restricted to non-database I/O.
Data File Functions
In order to use a data file it first must be opened.
scddopen will open any dBASEIII, dBASEIII+, or dBASEIV
compatible data file. The SoftC Database Library file
manager handle will be returned. This handle number must be
used for all I/O with that specific data file.
When you are finished with a data file it is good practice
to close that data file via a call to scddclose. This is
true for a couple of reasons: 1) the data will be safe if
your application crashes, and 2) computer memory will be
freed for other use. A safety net is provided by scdterm in
that it will close all data, memo, and index files open at
program termination.
The length of the data file in bytes can be found using
scddsize. The name of the data file associated with a
particular handle can be retrieved via a call to scddinfo.
Also a new data file can be created by scddcreate.
12
CHAPTER 3, A DATABASE TUTORIAL
Data Record I/O
Having a data file is of little use unless you can
manipulate the individual records. The library provides
seven functions to: read/write individual records,
delete/recover deleted records, manipulate I/O buffers, and
retrieve information about the record structure.
A data record can be read from the data file using scdrget.
The actual data will be placed in an internal buffer. See
the discussion on Data Field I/O for more information on
accessing the individual fields found in a data record. When
a data record needs to be written to the file, scdrput
should be used. This function is used both for the changing
of a record as well as adding new records.
dBASE data records are not physically removed from the data
file when they are deleted. This enables the user to change
his mind and recover the deleted records for use again. The
SoftC Database Library follows this guideline by providing
the scdrdel function to mark a data record as deleted, and
the scdrundel function to recover the record (or mark as
active).
Information about the data record structure can be retrieved
by a call to scdrinfo. The record length, number of fields
in the data record, and the addresses of the internal I/O
buffers can be obtained in this way.
Two additional functions are provided which deal exclusively
with the internal I/O buffers: scdrclear, and scdrcopy.
scdrclear is useful in clearing the output buffer before
placing data in the individual fields. The entire data
record will be set to spaces (" "). This has the effect on
numeric fields of placing nothing in the field rather than
zero. scdrcopy can be useful when a record needs to be
updated but the original also needs to be retained.
Data Field I/O
The ten data field manipulation functions provide for: the
writing and reading of data to and from fields in the
internal I/O buffer, the conversion of field names to field
numbers, and the retrieval of the field descriptions
originally setup with scddcreate.
13
CHAPTER 3, A DATABASE TUTORIAL
There are two types of field I/O: standard C types and
ASCIIZ string. scdfput and scdfget use the standard C types
below to place data in and retrieve data from individual
fields in a record. scdfput attempts to properly format the
data before placing it in the field. This means that the
proper number of spaces, zeros, and/or a decimal point will
be added as appropriate.
C types dBASE types
ASCIIZ string character
ASCIIZ string date
double dBASEIV BCD
char logical
unsigned long memo
double numeric
scdfputs and scdfgets use ASCIIZ strings exclusively. It is
left up to the users of these functions to ensure that the
data is properly formatted. Both "scdfput" functions work
with the internal output buffer, and the "scdfget" functions
work with the internal input buffer. There are also
"extended" versions of the preceding four functions
(scdfgetx, scdfgetsx, scdfputx, scdfputx respectively) which
allow the user to access either of the internal I/O buffers.
A function exists to retrieve the field descriptions (name,
type, length, number of decimal places) and the length of
the longest data field (scdfinfo). A field name to field
number translation function (scdfnam2no) is provided to
isolate your application from the structure of the data
files.
Memo File Functions
dBASE stores the memo file record number in the data file.
The "scdfget" functions return the record number and the
"scdfput" functions expect a valid memo record number.
Memo files are not automatically opened when the data files
are opened. These files must be explicitly opened via
scdtopen. Any dBASEIII+ compatible memo file can be opened
with this function. The SoftC Database Library file manager
handle will be returned on exit. This handle number must be
used for all I/O with that memo file.
14
CHAPTER 3, A DATABASE TUTORIAL
When you are finished with a memo file it should be closed
with a call to scdtclose. The name of the memo file
associated with a particular handle can be retrieved via a
call to scdtinfo. A new file can be created by scdtcreate.
dBASEIII inserts soft carriage returns in the memo data as
it is written to the file. scdfgett will return the contents
of the memo record with the soft carriage returns removed.
scdfgettx is an extended function which allows the user to
specify whether or not the soft carriage returns are
removed.
Two memo record output functions exist: 1) scdfputt will
automatically add soft carriage returns limiting memo line
length to the value found in sc_softlen, 2) scdfputtx allows
the user to specify whether or not soft carriage returns are
added and, if added, the line length. Note that the memo
file record number returned by these two functions should be
written into the appropriate data file field by using
scdfput.
Index File Functions
In order to use an index file it first must be opened.
scdnopen will open any dBASEIII, dBASEIII+, or dBASEIV
compatible index file (.NDX). The .NTX index files created
by Clipper and the .MDX index files created by dBASE IV are
not compatible with dBASE III (and thusly with this
library). The SoftC Database Library file manager handle
will be returned. This handle number must be used for all
I/O with that specific index file.
When you are finished with an index file, it can be closed
via a call to scdnclose. Information about the index file
such as the file name and length of the key expression can
be retrieved by a call to scdninfo. A new index file can be
created by using the function scdncreate.
scdnexpr can be used to get the actual index key expression.
This key expression is generally a formula listing the field
names used to make the index key. For example, FIRST_NAME
and LAST_NAME are both fields found in a data file, if an
index key was made from the combination of these fields the
key expression could be "LAST_NAME + FIRST_NAME".
15
CHAPTER 3, A DATABASE TUTORIAL
Index Page Functions
If memory is available the SoftC Database Library file
manager will allocate space for ten index pages. To change
the number of pages for which memory was allocated, scdpnum
can be used. scdpinfo is used to find out how many pages for
which space was allocated.
Index Key Functions
Twelve functions have been provided for use in: finding a
key, moving to the next or previous key, adding/deleting a
key, retrieving the current key, and building a key. There
are three search functions supported: find the first key
(scdkfirst), finding the last key (scdklast), and searching
for a specific key (scdkfind). The keys found in this manner
become the "current key". Wildcards such as "?" and "*"
cannot be used.
Once a particular key is found it is often desired to get
the key following (scdknext) or the key preceding (scdkprev)
it. These keys, if found, become the current key. Another
function is provided to return the current key, scdkcur.
It is also desirable to be able to add and delete keys from
the index file. scdkadd and scdkdel provide these functions.
These functions also attempt to keep the B-tree balanced, so
that one branch of the tree will not grow larger than the
others.
Two functions are supplied to convert date fields to valid
index keys: 1) scdkdate converts ASCIIZ date strings of
"mm/dd/yy", and 2) scdkdatex allows the user to specify the
date string format ("mm/dd/yy", "mm/dd/yyyy", or
"yyyymmdd").
dBASE provides certain functions which may be used in a key
expression. scdkmake will build a key for you using the
index key expression and the current contents of the
internal output buffer. This function supports five of the
more common dBASE functions: dtoc, left, right, str, and
substr (and the various legitimate combinations). Note that
this function is not necessary for single field character or
numeric keys, but it (or scdkdate) can be used for date
keys. scdkmakex is an extended form which allows the user to
select which I/O buffer to use when building a key.
16
Chapter 4
Clock & Calendar Functions
This chapter will describe the time and date functions
available in the SoftC Database Library. Currently there are
seventeen functions implemented: thirteen calendar, and
four clock. Note that the date format is "yyyymmdd" and the
time format is "hh:mm:ss" for all functions unless otherwise
specified.
Date String to String Conversion
Internal to dBASE the date fields are formatted as
"yyyymmdd". This format enables the date field to be used
properly as an index key and ensures that the date "February
13, 1989" will always be larger than the date "December 15,
1988". Note that this date format is not the one normally
used when entering or displaying dates. If fact dBASE uses
the date format "mm/dd/yy" when it displays dates.
A function sccdxlat was created to allow switching between
these two formats. An additional format is provided to
enable the year section of the date to more accurately
represent the year entered. This format is "mm/dd/yyyy".
Date String to Numeric Conversion
Along with ASCIIZ string dates, the library supports two
types of numeric dates: year, month, and day in integer
form, and number of elapsed days in long integer form.
sccds2n is used to convert from an ASCIIZ string to
integers, and sccds2l will convert from ASCIIZ string to
long integer.
Date Numeric to String Conversion
The library also supports the conversion to ASCIIZ strings,
where sccdn2s converts integers to a string and sccdl2s
converts a long integer to a string. Two additional
functions are included to return ASCIIZ strings for an
integer day (sccday) or month (sccmonth) input, for example
"Thursday", or "March".
17
CHAPTER 4, CLOCK & CALENDAR FUNCTIONS
Date String Calculations
Three functions are provided to perform date calculations:
sccddiff will compute the difference in days between two
dates, sccdperm and sccdpermi return the number of days
found in the month of the desired year. sccdperm requires an
ASCIIZ string and sccdpermi requires an integer year and
month as input.
Date Validation and Testing
Two functions are provided to test for leap year: one
requires a ASCIIZ string as input (sccleap) and the other an
integer (sccleapi). Also sccdvalid can be used to check the
validity of an ASCIIZ date string.
Time String to Numeric Conversion
sccts2n can be used to convert an ASCIIZ string to three
integers (hours, minutes, and seconds).
Time Numeric to String Conversion
A function is also provided to convert from integers to an
ASCIIZ string: scctn2s.
Time String Calculations
scctdiff can be used to calculate the difference between two
ASCIIZ time strings. The difference in seconds is returned
in a long integer.
Time Validation
A function is included in the library to validate an ASCIIZ
time character string: scctvalid.
18
Chapter 5
Miscellaneous Functions
This chapter will describe the miscellaneous functions found
in the SoftC Database Library.
Program Initialization
scdinit sets up the SoftC Database Library file manager.
Memory will be allocated for a variety of internal
structures. As previously mentioned this function should be
called only once at the beginning of your application.
Program Termination
scdterm is called at the end of your application. It will
close all dBASE files and free the memory allocated by
scdinit.
Library Version
The scdvers function has been provided to retrieve an ASCIIZ
string containing the version of the SoftC Database Library
you are currently using. This can then be printed by puts.
Errors and Warnings
A global variable sc_code will contain the results of the
last library function call executed. Errors are indicated by
negative numbers, warnings by positive numbers greater than
zero, and a zero indicates success. Most functions in the
library will NOT execute if sc_code contains an error.
Because the functions will not operate on errant
information, this feature provides a small measure of
security for your data.
During program debug it may be advantageous to print the
text message associated with the contents of sc_code. scemsg
will return the address of the message associated with the
contents of sc_code, which can then be printed by puts.
19
CHAPTER 5, MISCELLANEOUS FUNCTIONS
If you desire to clear an error or warning condition either
the global variable sc_code can be set to zero or the
function sceclr can be used. It is preferable to use the
function rather than the global variable.
See Appendix A for a complete list of error and warning
codes and their associated messages.
20
Chapter 6
The SoftC Database Library
This chapter contains a detailed description of each of the
functions in the library.
The following sample function description explains how to
use this portion of the SoftC Database Library Reference
Manual.
21
CHAPTER 6, THE SOFTC DATABASE LIBRARY
function name
USAGE
function(
modifier parameter[,...]);
The declaration syntax for function, "parameter"
names are underlined. The [,...] indicates that
other parameters and their modifiers may follow.
PROTOTYPE IN
This lists the header files in which the function
is prototyped.
DESCRIPTION
This describes what the function does, the
parameters it takes, and any details you need in
order to use function and the related routines
listed.
SEE ALSO
Routines related to the function about which you
may wish to read are listed here.
RETURN VALUE
The value(s) that the function returns (if any)
are listed here. The return value will also be set
in sc_code. A good return will always be equal to
zero (unless otherwise indicated in the function
description). Error returns are indicated by
negative numbers. Any warning codes are always
greater than zero.
EXAMPLE
A sample program listing demonstrating how the
function is used.
22
CHAPTER 6, THE SOFTC DATABASE LIBRARY
sccday
USAGE
signed int sccday(
signed char daystr[10],
signed char day );
PROTOTYPE IN
sc_base.h
DESCRIPTION
sccday returns the day of the week ASCIIZ string
in "daystr" for the day specified by "day". "day"
must be in the range of 0 (Sunday) to 6
(Saturday). The maximum length of the string
returned will be 9 plus the NULL byte.
SEE ALSO
sccmonth.
RETURN VALUE
SC_SUCCESS function successful
SC_BADDATE invalid date
SC_NULLPARM parameter address null
EXAMPLE
#include "sc_base.h"
void main()
{
char day[10];
scdinit(1);
sccday(day,0);
puts(day);
scdterm();
}
23
CHAPTER 6, THE SOFTC DATABASE LIBRARY
sccddiff
USAGE
signed int sccddiff(
signed long *diff,
signed char *date1,
signed char *date2 );
PROTOTYPE IN
sc_base.h
DESCRIPTION
sccddiff returns the difference in days between
"date1" and "date2". The two ASCIIZ date strings
can be in any order, but must be valid dates of
the format "yyyymmdd" (eg "19890213"). This is the
date format used internally by the library file
manager. sccdxlat can be used to translate an
existing date string to this format, or a date
string can be built using sccdn2s.
SEE ALSO
sccdxlat, sccdn2s, sccdvalid.
RETURN VALUE
SC_SUCCESS calculation successful
SC_BADDATE invalid date
SC_NULLPARM parameter address null
EXAMPLE
#include "sc_base.h"
void main()
{
signed long d;
24
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdinit(1);
sccddiff(&d,"19890213","19881217");
printf("%ld",d);
scdterm();
}
25
CHAPTER 6, THE SOFTC DATABASE LIBRARY
sccdl2s
USAGE
signed int sccdl2s(
signed char *string,
signed long date);
PROTOTYPE IN
sc_base.h
DESCRIPTION
sccdl2s converts a long "date" into an ASCIIZ
string "string" of the format "yyyymmdd". A check
is made to verify that "string" is a valid date
string before exiting.
SEE ALSO
sccds2l.
RETURN VALUE
SC_SUCCESS conversion successful
SC_BADDATE invalid date
SC_NULLPARM parameter address null
EXAMPLE
#include "sc_base.h"
void main()
{
signed char d[9];
scdinit(1);
sccdl2s(d,726489);
puts(d);
scdterm();
}
26
CHAPTER 6, THE SOFTC DATABASE LIBRARY
sccdn2s
USAGE
signed int sccdn2s(
signed char *string,
signed int year,
signed int month,
signed int day );
PROTOTYPE IN
sc_base.h
DESCRIPTION
sccdn2s converts three integer date values
("year","month", and "day") into an ASCIIZ string
"string" of the format "yyyymmdd". A check is made
to verify that "string" is a valid date string
before exiting.
SEE ALSO
sccdvalid, sccds2n.
RETURN VALUE
SC_SUCCESS conversion successful
SC_BADDATE invalid date
SC_NULLPARM parameter address null
EXAMPLE
#include "sc_base.h"
void main()
{
signed char d[9];
scdinit(1);
sccdn2s(d,1989,2,13);
27
CHAPTER 6, THE SOFTC DATABASE LIBRARY
puts(d);
scdterm();
}
28
CHAPTER 6, THE SOFTC DATABASE LIBRARY
sccdperm
USAGE
signed int sccdperm(
signed int *days,
signed char *date);
PROTOTYPE IN
sc_base.h
DESCRIPTION
sccdperm calculates the number of "days" in the
month for the year specified in "date". The date
must be of the format "yyyymmdd". This function
also senses leap year and will properly return 29
days for February.
SEE ALSO
sccdpermi.
RETURN VALUE
SC_SUCCESS conversion successful
SC_BADDATE invalid date
SC_NULLPARM parameter address null
EXAMPLE
#include "sc_base.h"
void main()
{
signed char d;
scdinit(1);
sccdperm(&d,"19890325");
printf("%d",d);
scdterm();
29
CHAPTER 6, THE SOFTC DATABASE LIBRARY
}
30
CHAPTER 6, THE SOFTC DATABASE LIBRARY
sccdpermi
USAGE
signed int sccdpermi(
signed int *days,
signed int year,
signed int month );
PROTOTYPE IN
sc_base.h
DESCRIPTION
sccdpermi calculates the number of "days" in
"month" for "year". This function also senses leap
year and will properly return 29 days for
February.
SEE ALSO
sccdperm.
RETURN VALUE
SC_SUCCESS conversion successful
SC_BADDATE invalid date
SC_NULLPARM parameter address null
EXAMPLE
#include "sc_base.h"
void main()
{
signed char d;
scdinit(1);
sccdpermi(&d,1989,3);
printf("%d",d);
scdterm();
31
CHAPTER 6, THE SOFTC DATABASE LIBRARY
}
32
CHAPTER 6, THE SOFTC DATABASE LIBRARY
sccds2l
USAGE
signed int sccds2l(
signed long *date,
signed char *string );
PROTOTYPE IN
sc_base.h
DESCRIPTION
sccds2l converts an ASCIIZ "string" into a long
"date". The date string must be of the format
"yyyymmdd". This date is a calculated count of
days since 1/1/0000. No attempt was made to adjust
for changes made in the calendar. This function is
used predominantly for date arithmetic,
calculating elapsed days, etc.
RETURN VALUE
SC_SUCCESS conversion successful
SC_BADDATE invalid date
SC_NULLPARM parameter address null
EXAMPLE
#include "sc_base.h"
void main()
{
signed long l;
scdinit(1);
sccds2l(&l,"19890323");
printf("%ld",l);
scdterm();
}
33
CHAPTER 6, THE SOFTC DATABASE LIBRARY
sccds2n
USAGE
signed int sccds2n(
signed int *year,
signed int *month,
signed int *day,
signed char *string );
PROTOTYPE IN
sc_base.h
DESCRIPTION
sccds2n converts dates from an ASCIIZ string
"string" of the format "yyyymmdd" to three integer
values ("year", "month", and "day"). A partial
check is made to verify that "string" is a valid
date string before attempting to convert.
SEE ALSO
sccdn2s.
RETURN VALUE
SC_SUCCESS conversion successful
SC_BADDATE invalid date
SC_NULLPARM parameter address null
EXAMPLE
#include "sc_base.h"
void main()
{
signed int y, m, d;
scdinit(1);
sccds2n(&y,&m,&d,"19890213");
34
CHAPTER 6, THE SOFTC DATABASE LIBRARY
printf("%d %d %d",y,m,d);
scdterm();
}
35
CHAPTER 6, THE SOFTC DATABASE LIBRARY
sccdvalid
USAGE
signed int sccdvalid(
signed char *string );
PROTOTYPE IN
sc_base.h
DESCRIPTION
sccdvalid tests the date ASCIIZ "string" passed
for validity: string properly formatted
("yyyymmdd"), valid day of month, valid month of
year.
RETURN VALUE
SC_SUCCESS valid date
SC_BADDATE invalid date
SC_NULLPARM parameter address null
EXAMPLE
#include "sc_base.h"
void main()
{
scdinit(1);
if (sccdvalid("19890213") == SC_SUCCESS)
puts("Good Date.");
else
puts("Bad Date.");
scdterm();
}
36
CHAPTER 6, THE SOFTC DATABASE LIBRARY
sccdxlat
USAGE
signed int sccdxlat(
signed char *dest,
signed char *source,
signed char method );
PROTOTYPE IN
sc_base.h
DESCRIPTION
sccdxlat translates from one date ASCIIZ string
format to another under control of "method".
Currently three translation methods are supported:
SC_2ASCII from "yyyymmdd" to "mm/dd/yy"
SC_2ASCIIL from "yyyymmdd" to "mm/dd/yyyy"
SC_2DBASE from "mm/dd/[yy]yy" to "yyyymmdd".
The maximum lengths of "dest" and "source" are 10
characters (plus the NULL byte).
Note that when converting using SC_2DBASE dates
such as "2/1/89" will be translated to "19890201".
RETURN VALUE
SC_SUCCESS translation successful
SC_BADCMD invalid translation method
SC_BADDATE invalid date
SC_NULLPARM parameter address null
37
CHAPTER 6, THE SOFTC DATABASE LIBRARY
EXAMPLE
#include "sc_base.h"
void main()
{
char date[11];
scdinit(1);
sccdxlat(date,"2/1/89",SC_2ASCII);
puts(date);
scdterm();
}
38
CHAPTER 6, THE SOFTC DATABASE LIBRARY
sccleap
USAGE
signed int sccleap(
signed char *leap );
PROTOTYPE IN
sc_base.h
DESCRIPTION
sccleap tests the ASCIIZ year string formatted as
"yyyymmdd" passed to it in "leap" to see if it is
a leap year.
SEE ALSO
sccleapi
RETURN VALUE
> 0 year was a leap year
SC_SUCCESS year was not a leap year
SC_BADDATE invalid date
SC_NULLPARM parameter address null
EXAMPLE
#include "sc_base.h"
void main()
{
scdinit(1);
if (sccleap("1989")
puts("Leap Year!");
else
puts("Normal Year.");
scdterm();
}
39
CHAPTER 6, THE SOFTC DATABASE LIBRARY
sccleapi
USAGE
signed int sccleapi(
signed int leap );
PROTOTYPE IN
sc_base.h
DESCRIPTION
sccleapi tests the integer year passed to it in
"leap" to see if it is a leap year.
SEE ALSO
sccleap
RETURN VALUE
> 0 year was a leap year
SC_SUCCESS year was not a leap year
SC_BADDATE invalid date
SC_NULLPARM parameter address null
EXAMPLE
#include "sc_base.h"
void main()
{
scdinit(1);
if (sccleap(1989)
puts("Leap Year!");
else
puts("Normal Year.");
scdterm();
}
40
CHAPTER 6, THE SOFTC DATABASE LIBRARY
sccmonth
USAGE
signed int sccmonth(
signed char monthstr[10],
signed char month );
PROTOTYPE IN
sc_base.h
DESCRIPTION
sccmonth returns the ASCIIZ month string in
"monthstr" for the month specified by "month".
"month" must be in the range of 1 (January) to 12
(December). The maximum length of the string
returned will be 9 plus the NULL byte.
SEE ALSO
sccday
RETURN VALUE
SC_SUCCESS function successful
SC_BADDATE invalid date
SC_NULLPARM parameter address null
EXAMPLE
#include "sc_base.h"
void main()
{
char month[10];
scdinit(1);
sccmonth(month,4);
puts(month);
scdterm();
41
CHAPTER 6, THE SOFTC DATABASE LIBRARY
}
42
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scctdiff
USAGE
signed int scctdiff(
signed long *diff,
signed char *time1,
signed char *time2 );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scctdiff returns the difference in seconds between
"time1" and "time2". The two ASCIIZ time strings
can be in any order, but must be valid times of
the format "hh:mm:ss" (eg "12:03:59"). A time
string can be built using scctn2s.
SEE ALSO
scctn2s, scctvalid.
RETURN VALUE
SC_SUCCESS calculation successful
SC_BADTIME invalid time
SC_NULLPARM parameter address null
EXAMPLE
#include "sc_base.h"
void main()
{
signed int d;
scdinit(1);
scctdiff(&d,"12:03:59","11:30:00");
printf("%ld",d);
43
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdterm();
}
44
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scctn2s
USAGE
signed int scctn2s(
signed char *string,
signed int hour,
signed int minute,
signed int second );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scctn2s converts three integer time values "hour",
"minute", and "second" into an ASCIIZ string
"string" of format "hh:mm:ss". A check is made to
verify that "string" is a valid time string before
exiting.
SEE ALSO
scctvalid, sccts2n.
RETURN VALUE
SC_SUCCESS conversion successful
SC_BADTIME invalid time
SC_NULLPARM parameter address null
EXAMPLE
#include "sc_base.h"
void main()
{
signed char d[9];
scdinit(1);
scctn2s(d,12,3,59);
45
CHAPTER 6, THE SOFTC DATABASE LIBRARY
puts(d);
scdterm();
}
46
CHAPTER 6, THE SOFTC DATABASE LIBRARY
sccts2n
USAGE
signed int sccts2n(
signed int *hour,
signed int *minute,
signed int *second,
signed char *string );
PROTOTYPE IN
sc_base.h
DESCRIPTION
sccts2n converts times from an ASCIIZ string
"string" of format "hh:mm:ss" to three integer
values "hour", "minute", and "second". A partial
check is made to verify that "string" is a valid
time string before attempting to convert.
SEE ALSO
scctn2s.
RETURN VALUE
SC_SUCCESS conversion successful
SC_BADTIME invalid time
SC_NULLPARM parameter address null
EXAMPLE
#include "sc_base.h"
void main()
{
signed int h, m, s;
scdinit(1);
sccts2n(&h,&m,&s,"12:03:59");
47
CHAPTER 6, THE SOFTC DATABASE LIBRARY
printf("%d %d %d",h,m,s);
scdterm();
}
48
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scctvalid
USAGE
signed int scctvalid(
signed char *string );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scctvalid tests the ASCIIZ time string "string"
passed for validity: string properly formatted
("hh:mm:ss"), valid hour, minute, and second.
RETURN VALUE
SC_SUCCESS valid time
SC_BADTIME invalid time
SC_NULLPARM parameter address null
EXAMPLE
#include "sc_base.h"
void main()
{
scdinit(1);
if (scctvalid("12:03:59") == SC_SUCCESS)
puts("Good Time.");
else
puts("Bad Time.");
scdterm();
}
49
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scddclose
USAGE
signed int scddclose(
signed char handle );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scddclose closes a data file and frees all
allocated memory associated with data file
"handle". If the data file was modified, today's
date will be written into the file header.
SEE ALSO
scddopen
RETURN VALUE
SC_SUCCESS data file closed
SC_CLOSFAIL file close failure
SC_BADHNDL data file not open or bad handle
SC_SKFAIL file seek failure
SC_WRTFAIL file header write failure
EXAMPLE
#include "sc_base.h"
void main()
{
char dbf;
scdinit(15);
if (scddopen(&dbf,"TEST.DBF") == SC_SUCCESS)
scddclose(dbf);
scdterm();
50
CHAPTER 6, THE SOFTC DATABASE LIBRARY
}
51
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scddcreate
USAGE
signed int scddcreate(
signed char *filename,
signed char numfields,
SC_FIELD fields[]);
PROTOTYPE IN
sc_base.h
DESCRIPTION
scddcreate creates a dBASEIII compatible data
file. A pointer to an array of SC_FIELD must be
passed.
typedef struct {
signed char name[11]; /* field name */
signed char type; /* field type */
unsigned char len; /* field length */
unsigned char decpl; /* decimal places */
} SC_FIELD;
The field description array must be initialized
and each element set to appropriate values. The
array determines the organization of the data
record. The data file does not remain open upon
exit of this function.
This function will create a new data file even if
one had already existed.
Field names and types are converted to all upper
case when the file is created.
52
CHAPTER 6, THE SOFTC DATABASE LIBRARY
Valid field types are:
'C' character (not NULL terminated in record)
'D' date ("yyyymmdd" format)
'L' logical (TRUE, FALSE)
'M' memo (memo file record number)
'N' numeric.
Restrictions:
The maximum record length is 4000 bytes.
The maximum number of fields is 128.
The maximum length of character fields is 254, and
they cannot be longer than 100 if used as a key.
The maximum length of numeric fields is 19.
The length of a date field is forced to 8.
The length of a logical field is forced to 1.
The length of a memo field is forced to 10.
The number of decimal places will be forced to
zero for all types except NUMERIC. For NUMERIC
fields it must be less than ('len' - 2) and also
less than 16. The number of decimal places cannot
be less than zero.
SEE ALSO
scddcreatex
RETURN VALUE
SC_SUCCESS data file created
SC_WRTFAIL disk write failure
SC_FLDCNT user supplied field description was
invalid
SC_BADFNAME invalid filename
SC_BADFLDT invalid field type
SC_BADFLDN field name invalid
SC_RECLEN record length error
SC_FLDLEN field length error
SC_DECPL decimal places parameter invalid
SC_NOHNDL no DOS file handles available
SC_NULLPARM parameter address null
EXAMPLE
#include "sc_base.h"
void main()
{
SC_FIELD fields[] = {
53
CHAPTER 6, THE SOFTC DATABASE LIBRARY
"character",'c',16,0, /* character field */
"date",'d',8,0, /* date field */
"logical",'l',1,0, /* logical field */
"memo",'m',0,0, /* memo field */
"numeric",'n',6,2 /* numeric field */
};
scdinit(15);
scddcreate("TEST.DBF",5,fields);
scdterm();
}
54
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scddcreatex
USAGE
signed int scddcreatex(
signed char *filename,
signed char numfields,
SC_FIELD fields[],
signed char style );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scddcreatex creates a dBASEIII or dBASEIV
compatible data file. A pointer to an array of
SC_FIELD must be passed.
typedef struct {
signed char name[11]; /* field name */
signed char type; /* field type */
unsigned char len; /* field length */
unsigned char decpl; /* decimal places */
} SC_FIELD;
The field description array must be initialized
and each element set to appropriate values. The
array determines the organization of the data
record. The data file does not remain open upon
exit of this function.
This function will create a new data file even if
one had already existed.
Field names and types are converted to all upper
case when the file is created.
55
CHAPTER 6, THE SOFTC DATABASE LIBRARY
Valid field types are:
'C' character (not NULL terminated in record)
'D' date ("yyyymmdd" format)
'F' floating point (valid only for dBASEIV files)
'L' logical (TRUE, FALSE)
'M' memo (memo file record number)
'N' numeric.
Both 'F' and 'N' fields are handled as doubles by
the library. The library does not support BCD
numbers.
The type of data file created depends upon the
value of the "style" parameter: SC_DB3 - dBASEIII
compatible, or SC_DB4 - dBASEIV compatible.
Restrictions:
The maximum record length is 4000 bytes.
The maximum number of dBASE III fields is 128, but
the maximum number of dBASEIV fields is 255.
The maximum length of character fields is 254, and
they cannot be longer than 100 if used as a key.
The maximum length of dBASE III numeric fields is
19, but the maximum length of dBASE IV numeric &
float fields is 20.
The length of a date field is forced to 8.
The length of a logical field is forced to 1.
The length of a memo field is forced to 10.
The number of decimal places will be forced to
zero for all types except: 1) dBASE III NUMERIC -
it must be less than ('len' - 2) and also less
than 16, and 2) dBASE IV NUMERIC and FLOAT - it
must be less than ('len' - 2). The number of
decimal places cannot be less than zero.
SEE ALSO
scddcreate
RETURN VALUE
SC_SUCCESS data file created
SC_WRTFAIL disk write failure
SC_FLDCNT user supplied field description was
invalid
SC_BADFNAME invalid filename
SC_BADFLDT invalid field type
56
CHAPTER 6, THE SOFTC DATABASE LIBRARY
SC_BADFLDN field name invalid
SC_RECLEN record length error
SC_FLDLEN field length error
SC_DECPL decimal places parameter invalid
SC_NOHNDL no DOS file handles available
SC_NULLPARM parameter address null
SC_DBFVERS invalid dBASE version
EXAMPLE
#include "sc_base.h"
void main()
{
SC_FIELD fields[] = {
"character",'c',16,0, /* character field */
"date",'d',8,0, /* date field */
"float",'f',10,3, /* float field */
"logical",'l',1,0, /* logical field */
"memo",'m',0,0, /* memo field */
"numeric",'n',6,2 /* numeric field */
};
scdinit(15);
scddcreatex("TEST.DBF",6,fields,SC_DB4);
scdterm();
}
57
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scddinfo
USAGE
signed int scddinfo(
signed char handle,
signed char *filename,
SC_DBFINFO *info );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scddinfo gets the name of the file associated with
"handle". It will also return a file information
structure "SC_DBFINFO".
typedef struct {
signed char style; /* file type (dBASEIII or
IV) */
signed char memo; /* memo file used flag */
signed char mdx; /* MDX file used flag */
signed char trans; /* transaction in
progress */
signed char encrypt; /* data file encrypted */
} SC_DBFINFO;
SEE ALSO
scddopen
RETURN VALUE
SC_SUCCESS returned the file name
SC_BADHNDL data file not open or bad handle
SC_NULLPARM parameter address null
58
CHAPTER 6, THE SOFTC DATABASE LIBRARY
EXAMPLE
#include <dir.h>
#include "sc_base.h"
void main()
{
char dbf;
char filename[MAXPATH];
SC_DBFINFO info;
scdinit(15);
if (scddopen(&dbf,"TEST.DBF") == SC_SUCCESS) {
scddinfo(dbf,filename,&info);
printf("%s\n",filename);
if (info.style == SC_DB3)
printf("dBASE III data file\n");
else {
printf("dBASE IV data file\n");
if (info.memo)
printf("memo file attached\n");
else
printf("no memo file attached\n");
if (info.mdx)
printf(".MDX file used\n")
else
printf("No .MDX file used\n");
if (info.trans)
printf("Transaction in progress\n");
if (info.encrypt)
printf("File encrypted\n");
}
scddclose(dbf);
}
scdterm();
}
59
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scddopen
USAGE
signed int scddopen(
signed char *handle,
signed char *filename );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scddopen opens a data file. Memory will be
allocated for a file packet and I/O buffers for
use internally by the SoftC Database Library file
manager. The data file will be tested as much as
possible to insure that it is a legitimate dBASE
data file.
All field names and types, and the file name will
be converted to upper case after the file has been
opened.
SEE ALSO
scddopenx,scddinfo
RETURN VALUE
SC_SUCCESS file opened and memory allocated
SC_MEMERR memory allocation failure
SC_NOFILE data file not found
SC_RDFAIL disk read failure
SC_SKFAIL disk seek failure
SC_NOHNDL no SoftC file handles available
SC_BADFNAME invalid filename
SC_NULLPARM parameter address null
SC_DBFVERS invalid dBASE version
SC_DBFHLEN header length error
SC_DBFDATE last update date in error
60
CHAPTER 6, THE SOFTC DATABASE LIBRARY
SC_RECLEN record length in error
SC_FILENGTH file length is incorrect
SC_BADFLDN invalid data field name
SC_BADFLDT invalid data field type
SC_MDXFLAG invalid multiple index flag
EXAMPLE
#include "sc_base.h"
void main()
{
char dbf;
scdinit(15);
if (scddopen(&dbf,"TEST.DBF") == SC_SUCCESS)
scddclose(dbf);
scdterm();
}
61
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scddopenx
USAGE
signed int scddopenx(
signed char *handle,
signed char *filename,
SC_DBFINFO *info );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scddopenx opens a data file. Memory will be
allocated for a file packet and I/O buffers for
use internally by the SoftC Database Library file
manager. The data file will be tested as much as
possible to insure that it is a legitimate dBASE
data file.
The structure SC_DBFINFO is used to return data
file status:
typedef struct {
signed char style; /* file type (dBASEIII or
IV) */
signed char memo; /* memo file used flag */
signed char mdx; /* MDX file used flag */
signed char trans; /* transaction in
progress */
signed char encrypt; /* data file encrypted */
} SC_DBFINFO;
All field names and types, and the file name will
be converted to upper case after the file has been
opened.
62
CHAPTER 6, THE SOFTC DATABASE LIBRARY
SEE ALSO
scddopen
RETURN VALUE
SC_SUCCESS file opened and memory allocated
SC_NOFILE data file not found
SC_RDFAIL disk read failure
SC_SKFAIL disk seek failure
SC_BADFNAME invalid filename
SC_NULLPARM parameter address null
SC_DBFVERS invalid dBASE version
SC_DBFHLEN header length error
SC_DBFDATE last update date in error
SC_RECLEN record length in error
SC_FILENGTH file length is incorrect
SC_BADFLDN invalid data field name
SC_BADFLDT invalid data field type
SC_MDXFLAG invalid multiple index flag
EXAMPLE
#include "sc_base.h"
void main()
{
char dbf;
SC_DBFINFO info;
scdinit(15);
if (scddopenx(&dbf,"TEST.DBF",&info) == SC_SUCCESS) {
printf("%s\n",filename);
if (info.style == SC_DB3)
printf("dBASE III data file\n");
else {
printf("dBASE IV data file\n");
if (info.memo)
printf("memo file attached\n");
else
printf("no memo file attached\n");
if (info.mdx)
printf(".MDX file used\n")
else
printf("No .MDX file used\n");
if (info.trans)
printf("Transaction in progress\n");
if (info.encrypt)
printf("File encrypted\n");
}
scddclose(dbf);
63
CHAPTER 6, THE SOFTC DATABASE LIBRARY
}
scdterm();
}
64
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scddsize
USAGE
signed int scddsize(
signed char handle,
signed long *recsused );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scddsize gets the number of records "recsused" in
the data file. This number will include all
records marked as inactive as well as all active
records.
RETURN VALUE
SC_SUCCESS returned the number of records
SC_BADHNDL data file not open or bad handle
SC_NULLPARM parameter address null
EXAMPLE
#include "sc_base.h"
void main()
{
char dbf;
long recsused;
scdinit(15);
if (scddopen(&dbf,"TEST.DBF") == SC_SUCCESS) {
scddsize(dbf,&recsused);
printf("%ld",recsused);
scddclose(dbf);
}
scdterm();
}
65
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdfget
USAGE
signed int scdfget(
signed char handle,
signed char fieldno,
void *data );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scdfget gets data from the desired field "fieldno"
of the input buffer. "data" will be converted from
dBASE to a more natural data type for 'c':
dBASE field type returned data type
'C' signed char *
'D' signed char [9]
'F' double (dBASEIV)
'L' signed char
'M' unsigned long
'N' double
Date and character fields are returned as ASCIIZ
strings. The date strings will be formatted as
"mm/dd/yy".
Data returned by this function for memo fields is
the memo file record number NOT the actual memo
text. A call must be made to either scdfgett or
scdfgettx to retrieve the memo text.
scdfinfo can be used to determine the length of
the longest data field in the file.
66
CHAPTER 6, THE SOFTC DATABASE LIBRARY
Note that fields are numbered from zero (0).
SEE ALSO
scdfgett, scdfgettx, scdfgets, scdfgetx, scdfput,
scdfinfo, scdrget.
RETURN VALUE
SC_SUCCESS retrieved data from field
SC_BADHNDL data file not open or bad handle
SC_NULLPARM parameter address null
SC_FLDCNT invalid number of fields
SC_BADDATE invalid date
EXAMPLE
#include "sc_base.h"
void main()
{
char dbf, character[17],logical,date[9];
double numeric;
unsigned long memo;
scdinit(15);
if (scddopen(&dbf,"TEST.DBF") == SC_SUCCESS) {
scdrget(dbf,1L);
scdfgets(dbf,0,character);
scdfget(dbf,1,(void *) date);
scdfget(dbf,2,(void *) &logical);
scdfget(dbf,3,(void *) &memo);
scdfget(dbf,4,(void *) &numeric);
printf("%s %s %c %lu %lf\n",
character,date,logical,memo,numeric);
scddclose(dbf);
}
scdterm();
}
67
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdfgets
USAGE
signed int scdfgets(
signed char handle,
signed char fieldno,
char *data );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scdfgets gets data from the desired field
"fieldno" of the input buffer. "data" will be
returned as an ASCIIZ string.
scdfinfo can be used to determine the length of
the longest data field in the file.
Note that date fields are returned in the form
"yyyymmdd". There is a difference between the date
formats of scdfgets and scdfget.
Note that fields are numbered from zero (0).
SEE ALSO
scdfget, scdfgetsx, scdfputs, scdfinfo, scdrget.
RETURN VALUE
SC_SUCCESS retrieved data from field
SC_BADHNDL data file not open or bad handle
SC_NULLPARM parameter address null
SC_FLDCNT invalid number of fields
SC_BADDATE invalid date
68
CHAPTER 6, THE SOFTC DATABASE LIBRARY
EXAMPLE
#include "sc_base.h"
void main()
{
char dbf, character[17], logical, date[9];
double numeric;
unsigned long
scdinit(15);
if (scddopen(&dbf,"TEST.DBF") == SC_SUCCESS) {
scdrget(dbf,1L);
scdfgets(dbf,0,character);
scdfgets(dbf,1,date);
scdfget(dbf,2,(void *) &logical);
scdfget(dbf,3,(void *) &memo);
scdfget(dbf,4,(void *) &numeric);
printf("%s %s %c %lu %lf\n",
character,date,logical,memo,numeric);
scddclose(dbf);
}
scdterm();
}
69
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdfgetsx
USAGE
signed int scdfgetsx(
signed char handle,
signed char fieldno,
char *data,
signed int buffer );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scdfgetsx is an extended version of scdfgets which
extracts data from the desired field "fieldno" of
the I/O buffer specified by "buffer". Use SC_INPUT
for the input buffer and SC_OUTPUT for the output
buffer. "data" will be returned as an ASCIIZ
string.
scdfinfo can be used to determine the length of
the longest data field in the file.
Note that date fields are returned in the form
"yyyymmdd". There is a difference between the date
formats of scdfgetsx and scdfgetx.
Note that fields are numbered from zero (0).
SEE ALSO
scdfgets, scdfgetx, scdfputs, scdfinfo, scdrget.
RETURN VALUE
SC_SUCCESS retrieved data from field
SC_BADHNDL data file not open or bad handle
70
CHAPTER 6, THE SOFTC DATABASE LIBRARY
SC_NULLPARM parameter address null
SC_FLDCNT invalid number of fields
SC_BADDATE invalid date
SC_BADCMD invalid I/O buffer selection
EXAMPLE
#include "sc_base.h"
void main()
{
char dbf, character[17], logical, date[9];
double numeric;
unsigned long memo;
scdinit(15);
if (scddopen(&dbf,"TEST.DBF") == SC_SUCCESS) {
scdrget(dbf,1L);
scdfgetsx(dbf,0,character,SC_INPUT);
scdfgetsx(dbf,1,date,SC_INPUT);
scdfgetx(dbf,2,(void *) &logical,SC_INPUT);
scdfgetx(dbf,3,(void *) &memo,SC_INPUT);
scdfgetx(dbf,4,(void *) &numeric,SC_INPUT);
printf("%s %s %c %lu %lf\n",
character,date,logical,memo,numeric);
scddclose(dbf);
}
scdterm();
}
71
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdfgett
USAGE
signed int scdfgett(
signed char handle,
signed long recno,
signed char **data );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scdfgett reads the desired record "recno" from the
memo file specified by "handle". A buffer large
enough to hold the text will be allocated the
address of which is returned in "data". The soft
carriage returns embedded in the text will be
removed.
SEE ALSO
scdfget, scdfgettx, scdfputt.
RETURN VALUE
SC_SUCCESS retrieved data from file
SC_BADHNDL memo file not open or bad handle
SC_NULLPARM parameter address null
SC_SKFAIL seek failure
SC_RDFAIL file read failure
SC_MEMERR memory allocation failure
SC_FLDLEN invalid field length
SC_FILBAD file may be corrupted
EXAMPLE
#include "sc_base.h"
void main()
72
CHAPTER 6, THE SOFTC DATABASE LIBRARY
{
char dbt, *data;
scdinit(15);
if (scdtopen(&dbt,"TEST.DBT") == SC_SUCCESS) {
scdfgett(dbt,1L,&data);
puts(data);
scddclose(dbt);
}
scdterm();
}
73
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdfgettx
USAGE
signed int scdfgettx(
signed char handle,
signed long recno,
signed char **data,
signed int command );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scdfgettx is an extended version of scdfgett which
allows the user to control whether or not the soft
carriage returns are stripped via "command". Use
SC_CRUNCHNG to leave the soft carriage returns
alone, or use SC_CRDELETE to remove them.
SEE ALSO
scdfgett.
RETURN VALUE
SC_SUCCESS retrieved data from file
SC_BADHNDL memo file not open or bad handle
SC_NULLPARM parameter address null
SC_SKFAIL seek failure
SC_RDFAIL file read failure
SC_MEMERR memory allocation failure
SC_FLDLEN invalid field length
SC_FILBAD file may be corrupted
SC_BADCMD invalid command
EXAMPLE
#include "sc_base.h"
74
CHAPTER 6, THE SOFTC DATABASE LIBRARY
void main()
{
char dbt, *data;
scdinit(15);
if (scdtopen(&dbt,"TEST.DBT") == SC_SUCCESS) {
scdfgettx(dbt,1L,&data,SC_CRDELETE);
puts(data);
scddclose(dbt);
}
scdterm();
}
75
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdfgetx
USAGE
signed int scdfgetx(
signed char handle,
signed char fieldno,
char *data,
signed int buffer );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scdfgetx is an extended version of scdfget which
extracts data from the desired field "fieldno" of
the I/O buffer specified by "buffer". Use SC_INPUT
for the input buffer and SC_OUTPUT for the output
buffer.
dBASE field type returned data type
'C' signed char *
'D' signed char [9]
'F' double (dBASEIV)
'L' signed char
'M' unsigned long
'N' double
Date and character fields are returned as ASCIIZ
strings. The date strings will be formatted as
"mm/dd/yy". There is a difference between the date
formats of scdfgetx and scdfgets.
Data returned by this function for memo fields is
the memo file record number NOT the actual memo
text. A call must be made to either scdfgett or
scdfgettx to retrieve the memo text.
76
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdfinfo can be used to determine the length of
the longest data field in the file.
Note that fields are numbered from zero (0).
SEE ALSO
scdfget, scdfgetsx, scdfput, scdfinfo, scdrget.
RETURN VALUE
SC_SUCCESS retrieved data from field
SC_BADHNDL data file not open or bad handle
SC_NULLPARM parameter address null
SC_FLDCNT invalid number of fields
SC_BADDATE invalid date
SC_BADCMD invalid I/O buffer selection
EXAMPLE
#include "sc_base.h"
void main()
{
char dbf, character[17], logical, date[9];
double numeric;
unsigned long memo;
scdinit(15);
if (scddopen(&dbf,"TEST.DBF") == SC_SUCCESS) {
scdrget(dbf,1L);
scdfgetsx(dbf,0,character,SC_INPUT);
scdfgetsx(dbf,1,date,SC_INPUT);
scdfgetx(dbf,2,(void *) &logical,SC_INPUT);
scdfgetx(dbf,3,(void *) &memo,SC_INPUT);
scdfgetx(dbf,4,(void *) &numeric,SC_INPUT);
printf("%s %s %c %lu %lf\n",
character,date,logical,memo,numeric);
scddclose(dbf);
}
scdterm();
}
77
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdfinfo
USAGE
signed int scdfinfo(
signed char handle,
signed char *longfldlen,
SC_FIELD *fields );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scdfinfo copies the data field descriptions to
"fields" using the structure SC_FIELD. The length
of the longest data field is also returned
"longfldlen".
typedef struct {
signed char name[11]; /* field name */
signed char type; /* field type */
unsigned char len; /* field length */
unsigned char decpl; /* decimal places */
} SC_FIELD;
The user must ensure that the array defined for
"fields" is large enough to hold all of the field
descriptions because scdfinfo blindly copies the
descriptions to "fields". Severe program errors
can be the result if the field array is too small.
Use scdrinfo to determine the number of fields in
the data record.
SEE ALSO
scdrinfo
78
CHAPTER 6, THE SOFTC DATABASE LIBRARY
RETURN VALUE
SC_SUCCESS returned the field descriptions
SC_BADHNDL data file not open or bad handle
SC_NULLPARM parameter address null
EXAMPLE
#include "sc_base.h"
void main()
{
char dbf, longfld, numflds, a;
SC_FIELD fields[128]; /* dBASEIII max size */
short reclen;
void *ibfr, *obfr;
scdinit(15);
if (scddopen(&dbf,"TEST.DBF") == SC_SUCCESS) {
scdrinfo(dbf,&reclen,&numflds,&ibfr,&obfr);
scdfinfo(dbf,&longfld,fields);
printf("longest field length = %d\n",longfld);
for (a = 0; a < numflds; a++)
printf("%s %c %d %d\n", fields[a].name,
fields[a].type,
fields[a].len, fields[a].decpl);
scddclose(dbf);
}
scdterm();
}
79
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdfnam2no
USAGE
signed int scdfnam2no(
signed char handle,
signed int *fieldno,
signed char *fieldname );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scdfnam2no searches through the field description
array for data file "handle" looking for
"fieldname". It will return the corresponding
field number.
Note that data files created by the SoftC Database
Library will have field names and types changed to
all upper case.
RETURN VALUE
SC_SUCCESS field number returned
SC_BADHNDL data file not open or bad handle
SC_BADFLDN invalid data record field name
SC_NULLPARM parameter address null
EXAMPLE
#include "sc_base.h"
void main()
{
char dbf, fldno
scdinit(15);
if (scddopen(&dbf,"TEST.DBF") == SC_SUCCESS) {
80
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdfnam2no(dbf,&fldno,"LOGICAL");
printf("%d",fldno);
scddclose(dbf);
}
scdterm();
}
81
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdfput
USAGE
signed int scdfput(
signed char handle,
signed char fieldno,
void *data );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scdfput will convert "data" from 'c' format to
dBASE format and place it in the proper field
"fieldno" of the output buffer.
dBASE field type returned data type
'C' signed char *
'D' signed char [9]
'L' signed char
'M' unsigned long
'N' double
Note that fields are numbered from zero (0).
Note that scdfput follows the date formatting
standard of scdfget. It is optional to include the
"19" from "1989" as this is assumed, however the
date "2/1/00" will become "19000201" even if you
had intended it to be "20000201". Date strings can
be formatted as "2/1/2000" to overcome this
problem.
SEE ALSO
scdfget, scdfputs, scdfputx.
82
CHAPTER 6, THE SOFTC DATABASE LIBRARY
RETURN VALUE
SC_SUCCESS data placed in field
SC_BADHNDL data file not open or bad handle
SC_NULLPARM parameter address null
SC_BADDATE invalid date field
SC_FLDTRUNC character field truncated
SC_BADDATA bad data to be written
SC_FLDCNT invalid field number
SC_FLDROUND numeric field rounded
EXAMPLE
#include "sc_base.h"
void main()
{
char dbf, logical = 'T', date[9] = "12/25/88";
long recno;
double numeric = 20.0L;
unsigned long memo = 1L;
scdinit(15);
if (scddopen(&dbf,"TEST.DBF") == SC_SUCCESS) {
scdfputs(dbf,0,"SoftC Database Library ");
scdfput(dbf,1,(void *) date);
scdfput(dbf,2,(void *) &logical);
scdfput(dbf,3,(void *) &memo)
scdfput(dbf,4,(void *) &numeric);
scdrput(dbf,&recno,SC_ADD);
printf("Record number = %ld\n",recno);
scddclose(dbf);
}
scdterm();
}
83
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdfputs
USAGE
signed int scdfputs(
signed char handle,
signed char fieldno,
char *data );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scdfputs will place "data" in the proper field
"fieldno" of the output buffer. It is the user's
responsibility to provide a properly sized and
formatted ASCIIZ string to scdfputs.
Note that fields are numbered from zero (0).
Note that scdfputs follows the date formatting
conventions of scdfgets. Also be aware that the
date formatting conventions of scdfget/scdfput are
not the same as scdfgets/scdfputs.
SEE ALSO
scdfgets, scdfput, scdfputsx.
RETURN VALUE
SC_SUCCESS data placed in field
SC_BADHNDL data file not open or bad handle
SC_NULLPARM parameter address null
SC_BADDATE invalid date field
SC_FLDTRUNC character field truncated
SC_BADDATA bad data to be written
SC_FLDCNT invalid field number
84
CHAPTER 6, THE SOFTC DATABASE LIBRARY
EXAMPLE
#include "sc_base.h"
void main()
{
char dbf, logical,date[9];
long recno;
double numeric;
unsigned long memo;
scdinit(15);
if (scddopen(&dbf,"TEST.DBF") == SC_SUCCESS) {
scdfputs(dbf,0,"SoftC Database library ");
scdfputs(dbf,1, date);
scdfput(dbf,2,(void *) &logical);
scdfput(dbf,3,(void *) &memo);
scdfput(dbf,4,(void *) &numeric);
scdrput(dbf,&recno,SC_ADD);
printf("Record number = %ld\n",recno);
scddclose(dbf);
}
scdterm();
}
85
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdfputsx
USAGE
signed int scdfputsx(
signed char handle,
signed char fieldno,
char *data,
signed int buffer );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scdfputsx is an extended version of scdfputs which
allows the placement of "data" in the proper field
"fieldno" of the I/O buffer specified by "buffer".
Use SC_INPUT for the input buffer and SC_OUTPUT
for the output buffer. It is the user's
responsibility to provide a properly sized and
formatted ASCIIZ string to scdfputsx.
Note that fields are numbered from zero (0).
Note that scdfputsx follows the date formatting
conventions of scdfgets. Also be aware that the
date formatting conventions of scdfget/scdfput are
not the same as scdfgets/scdfputsx.
SEE ALSO
scdfgets, scdfput, scdfputs.
RETURN VALUE
SC_SUCCESS data placed in field
SC_BADHNDL data file not open or bad handle
SC_NULLPARM parameter address null
SC_BADDATE invalid date field
86
CHAPTER 6, THE SOFTC DATABASE LIBRARY
SC_FLDTRUNC character field truncated
SC_BADDATA bad data to be written
SC_FLDCNT invalid field number
SC_FLDROUND numeric field rounded
SC_BADCMD invalid I/O buffer selection
EXAMPLE
#include "sc_base.h"
void main()
{
char dbf, logical,date[9];
long recno;
double numeric;
unsigned long memo;
scdinit(15);
if (scddopen(&dbf,"TEST.DBF") == SC_SUCCESS) {
scdfputsx(dbf,0,"SoftC Database Library ",SC_OUTPUT);
scdfputsx(dbf,1, date,SC_OUTPUT);
scdfputx(dbf,2,(void *) &logical,SC_OUTPUT);
scdfputx(dbf,3,(void *) &memo,SC_OUTPUT);
scdfputx(dbf,4,(void *) &numeric,SC_OUTPUT);
scdrput(dbf,&recno,SC_ADD);
printf("Record number = %ld\n",recno);
scddclose(dbf);
}
scdterm();
}
87
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdfputt
USAGE
signed int scdfputt(
signed char handle,
signed long *recno,
signed char *data );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scdfputt writes "data" to the memo file specified
by "handle". The record number written is returned
in "recno". This record number must be then
written to the data output buffer via a call to
scdfput. This function assumes that "data" is an
ASCIIZ string with a maximum length of 65,536
characters.
Soft carriage returns will be added into the memo
record so as to limit the line length to the value
contained in sc_softlen. This global variable is
initially set to 66. There are limits to the
values allowed in sc_softlen: it cannot be less
than 10 nor greater than 132. If it is set to zero
(0) then no soft carriage returns will be added.
SEE ALSO
scdfgett, scdfput, scdfputtx.
RETURN VALUE
SC_SUCCESS data written to file
SC_BADHNDL memo file not open or bad handle
SC_NULLPARM parameter address null
SC_SKFAIL seek failure
SC_LINELEN invalid soft line length
88
CHAPTER 6, THE SOFTC DATABASE LIBRARY
EXAMPLE
#include "sc_base.h"
void main()
{
char dbt, data[512];
long recno;
scdinit(15);
if (scdtopen(&dbt,"TEST.DBT") == SC_SUCCESS) {
strcpy(data,"hello world.");
scdfputt(dbt,&recno,data);
printf("%ld",recno);
scddclose(dbt);
}
scdterm();
}
89
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdfputtx
USAGE
signed int scdfputtx(
signed char handle,
signed long *recno,
signed char *data,
signed int linelength );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scdfputtx is an extended version of scdfputt which
allows the user to directly control whether or not
the soft carriage returns are added and, if so,
where. If "linelength" is zero (0) no soft
carriage returns will be added, else "linelength"
specifies the maximum length of a memo line.
Note that existing soft carriage returns are not
removed before new ones are added.
SEE ALSO
scdfputt.
RETURN VALUE
SC_SUCCESS data written to file
SC_BADHNDL memo file not open or bad handle
SC_NULLPARM parameter address null
SC_SKFAIL seek failure
SC_LINELEN invalid soft line length
90
CHAPTER 6, THE SOFTC DATABASE LIBRARY
EXAMPLE
#include "sc_base.h"
void main()
{
char dbt, data[512];
long recno;
scdinit(15);
if (scdtopen(&dbt,"TEST.DBT") == SC_SUCCESS) {
strcpy(data,"hello world.");
scdfputtx(dbt,&recno,data,sc_softlen);
printf("%ld",recno);
scddclose(dbt);
}
scdterm();
}
91
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdfputx
USAGE
signed int scdfputx(
signed char handle,
signed char fieldno,
void *data,
signed int buffer );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scdfputx is an extended version of scdfput which
allows the placement of "data" in the proper field
"fieldno" of the I/O buffer specified by "buffer".
Use SC_INPUT for the input buffer and SC_OUTPUT
for the output buffer.
dBASE field type: returned data type:
'C' signed char *
'D' signed char [9]
'L' signed char
'M' unsigned long
'N' double
Note that fields are numbered from zero (0).
Note that scdfputx follows the date formatting
standard of scdfget. It is optional to include the
"19" from "1989" as this is assumed, however the
date "2/1/00" will become "19000201" even if you
had intended it to be "20000201". Date strings can
be formatted as "2/1/2000" to overcome this
problem. Also be aware that the date formatting
conventions of scdfget/scdfputx are not the same
as scdfgets/scdfputs.
92
CHAPTER 6, THE SOFTC DATABASE LIBRARY
SEE ALSO
scdfgets, scdfput, scdfputs.
RETURN VALUE
SC_SUCCESS data placed in field
SC_BADHNDL data file not open or bad handle
SC_NULLPARM parameter address null
SC_BADDATE invalid date field
SC_FLDTRUNC character field truncated
SC_BADDATA bad data to be written
SC_FLDCNT invalid field number
SC_FLDROUND numeric field rounded
SC_BADCMD invalid I/O buffer selection
EXAMPLE
#include "sc_base.h"
void main()
{
char dbf, logical,date[9];
long recno;
double numeric;
unsigned long memo;
scdinit(15);
if (scddopen(&dbf,"TEST.DBF") == SC_SUCCESS) {
scdfputsx(dbf,0,"SoftC Database Library ",SC_OUTPUT);
scdfputsx(dbf,1, date,SC_OUTPUT);
scdfputx(dbf,2,(void *) &logical,SC_OUTPUT);
scdfputx(dbf,3,(void *) &memo,SC_OUTPUT);
scdfputx(dbf,4,(void *) &numeric,SC_OUTPUT);
scdrput(dbf,&recno,SC_ADD);
printf("Record number = %ld\n",recno);
scddclose(dbf);
}
scdterm();
}
93
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdinit
USAGE
signed int scdinit(
signed char files );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scdinit is called once and only once at the
beginning of the program. The maximum number of
simultaneously open "files" is passed. This
function sets up the SoftC Database Library file
manager environment for processing. Memory will be
allocated for a variety of control structures used
internally by the file manager.
Note: DOS defaults to a maximum of 20 open files
per program. The first five are taken up with
printer, console, auxiliary port, etc. leaving
only 15 file handles available per program. So
passing a value greater than 15 in "files" will
only waste memory.
Note that neither Microsoft C 5.1 nor Turbo C 2.0
support more than 20 open files.
SEE ALSO
scdterm.
RETURN VALUE
SC_SUCCESS completed initialization
SC_MEMERR memory allocation failure
SC_BADHNDL invalid number of handles
94
CHAPTER 6, THE SOFTC DATABASE LIBRARY
EXAMPLE
#include "sc_base.h"
void main()
{
scdinit(15);
scdterm();
}
95
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdkadd
USAGE
signed int scdkadd(
signed char handle,
signed char *key,
signed long recno );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scdkadd will add "key" to the index file specified
by "handle". "recno" is the data record number to
be associated with "key" (the data record pointed
to by recno must exist prior to calling scdkadd).
Note that when adding character keys it is not
necessary to pad the key string to size with
spaces (" "), the function will automatically do
this for you.
SEE ALSO
scdkdate, scdkmake.
RETURN VALUE
SC_SUCCESS key added to index file
SC_BADHNDL index file not open or bad handle
SC_SKFAIL disk seek failure
SC_WRTFAIL disk write failure
SC_RDFAIL disk read failure
SC_MEMERR memory allocation failure
SC_NULLPARM parameter address null
96
CHAPTER 6, THE SOFTC DATABASE LIBRARY
EXAMPLE
#include <string.h>
#include "sc_base.h"
void main()
{
char dbf, ndx, date[9];
short result;
long recno;
scdinit(15);
if (scddopen(&dbf,"TEST.DBF") == SC_SUCCESS) {
if (scdnopen(&ndx,"TEST.NDX") == SC_SUCCESS) {
strcpy(date,"19881201");
scdfputs(dbf,1,date);
result = scdrput(dbf,&recno,SC_ADD)
if (result == SC_SUCCESS)
scdkadd(ndx,date,recno);
scdnclose(ndx);
}
scddclose(dbf)
}
scdterm();
}
97
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdkcur
USAGE
signed int scdkcur(
signed char handle,
signed char *key,
signed long *recno );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scdkcur will return the key value "key" and data
record number "recno" associated with the current
key in the index file.
The current key pointer must be set by a call to
either scdkfind, scdkfirst, scdklast, scdknext, or
scdkprev before calling scdkcur.
The user must ensure that the buffer used to
return the key is large enough to hold the entire
key. The maximum length of the key can be
determined via a call to scdninfo.
SEE ALSO
scdninfo, scdkfind, scdkfirst, scdklast, scdknext,
scdkprev.
RETURN VALUE
SC_SUCCESS key and recno returned
SC_BADHNDL index file not open or bad handle
SC_END no current key
SC_RDFAIL read index file failure
SC_SKFAIL seek failure (bad record address or seek
fail)
98
CHAPTER 6, THE SOFTC DATABASE LIBRARY
SC_NULLPARM parameter address null
EXAMPLE
#include "sc_base.h"
void main()
{
char ndx, date[9], dat[9];
long recno, recn;
scdinit(15);
if (scdnopen(&ndx,"TEST.NDX") == SC_SUCCESS) {
date[8] = 0;
dat[8] = 0;
scdkfirst(ndx,date,&recn);
scdkcur(ndx,dat,&recno);
printf("%s %s %ld %ld\n", date,dat,recno,recn);
scdnclose(ndx);
}
scdterm();
}
99
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdkdate
USAGE
signed int scdkdate(
double *key,
signed char *string );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scdkdate will translate an ASCIIZ date string
"string" of format "yyyymmdd" into a valid dBASE
date key "key".
RETURN VALUE
SC_SUCCESS index key created
SC_NULLPARM parameter address null
SC_BADDATE invalid date string
EXAMPLE
#include <string.h>
#include "sc_base.h"
void main()
{
double key;
scdinit(15);
scdkdate(&key,"19890801");
printf("%lf",key);
scdterm();
}
100
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdkdatex
USAGE
signed int scdkdatex(
double *key,
signed char *string,
signed int method );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scdkdatex is an extended form of scdkdate which
allows the user to translate an ASCIIZ date string
"string" of either "yyyymmdd", "mm/dd/yy", or
"mm/dd/yyyy" format into a valid dBASE date key
"key".
Use "method" of SC_DBASE to translate "yyyymmdd"
strings, and SC_ASCII for "mm/dd/yy" or
"mm/dd"yyyy".
RETURN VALUE
SC_SUCCESS index key created
SC_NULLPARM parameter address null
SC_BADDATE invalid date string
EXAMPLE
#include <string.h>
#include "sc_base.h"
void main()
{
double key;
scdinit(15);
101
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdkdatex(&key,"19890801",SC_DBASE);
printf("%lf",key);
scdterm();
}
102
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdkdel
USAGE
signed int scdkdel(
signed char handle,
signed char *key,
signed long recno );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scdkdel will remove "key" from the index file
specified by "handle". "recno" is used along with
"key" to ensure that the proper key has been
removed from the index file.
Note that when deleting character keys it is not
necessary to pad the key string to size with
spaces (" "), the function will automatically do
this for you.
SEE ALSO
scdkadd.
RETURN VALUE
SC_SUCCESS key removed from index file
SC_BADHNDL index file not open or bad handle
SC_SKFAIL disk seek failure
SC_WRTFAIL disk write failure
SC_RDFAIL index file read failure
SC_EMPTY index file is empty - no keys found
SC_NOFIND desired key was not found
SC_NULLPARM parameter address null
SC_FILBAD index file may be corrupted
103
CHAPTER 6, THE SOFTC DATABASE LIBRARY
EXAMPLE
#include <string.h>
#include "sc_base.h"
void main()
{
char ndx, date[9];
long recno;
scdinit(15);
if (scdnopen(&ndx,"TEST.NDX") == SC_SUCCESS) {
strcpy(date,"19881202");
recno = 7L;
scdkdel(ndx,date,recno);
scdnclose(ndx);
}
scdterm();
}
104
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdkfind
USAGE
signed int scdkfind(
signed char handle,
signed char *key,
signed long *recno,
signed char method );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scdkfind supports two key search methods
(determined by "method"): SC_EXACT - find an exact
match with "key" and "recno", and SC_FIRST - find
the first logical occurrence of "key" in the index
and return the associated record number "recno" if
found.
If a match cannot be found, the current key will
be the physical key which would immediately
precede "key". The current key's value and data
record number will be returned in "key" and
"recno".
The user must ensure that the buffer used to
return the key is large enough to hold the entire
key. The maximum length of the key can be
determined via a call to scdninfo.
Note that when searching using character keys it
is not necessary to pad the key string to size
with spaces (" "), the function will automatically
do this for you.
105
CHAPTER 6, THE SOFTC DATABASE LIBRARY
Note that searching for partial keys can be
accomplished by using the SC_FIRST method. For
example, you are using a fifteen character key
size. You want to find the first entry where the
first five characters are "ABCDE". All you need do
is copy that five character ASCIIZ string into
your key buffer and then call scdkfind. The
function will space pad to length and then find
the first matching entry.
Note that numeric keys are returned as doubles,
and character keys are returned as strings.
SEE ALSO
scdninfo.
RETURN VALUE
SC_SUCCESS key found
SC_NOFIND key not found
SC_EMPTY index file empty - no keys found
SC_BADHNDL index file not open or bad handle
SC_SKFAIL seek failure (bad record address or seek
fail)
SC_RDFAIL read index file failure
SC_NULLPARM parameter address null
EXAMPLE
#include <string.h>
#include "sc_base.h"
void main()
{
char ndx, key[16];
long recno;
int result;
scdinit(15);
if (scdnopen(&ndx,"TEST.NDX") == SC_SUCCESS) {
strcpy(key,"ABCDE");
recno = 7L;
if (scdkfind(ndx,key,&recno,SC_FIRST) != SC_SUCCESS
printf("%s\n",scemsg());
scddclose(ndx);
}
scdterm();
}
106
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdkfirst
USAGE
signed int scdkfirst(
signed char handle,
signed char *key,
signed long *recno );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scdkfirst will set the current key pointer to the
first logical key in the index and return the key
value "key" and data record number "recno"
associated with the new current key.
The user must ensure that the buffer used to
return the key is large enough to hold the entire
key. The maximum length of the key can be
determined via a call to scdninfo.
Note that numeric keys are returned as doubles,
and character keys are returned as strings.
SEE ALSO
scdninfo.
RETURN VALUE
SC_END successfully found the first key
SC_BADHNDL index file not open or bad handle
SC_EMPTY index file empty - no keys found
SC_SKFAIL seek failure
SC_RDFAIL read index file failure
SC_NULLPARM parameter address null
107
CHAPTER 6, THE SOFTC DATABASE LIBRARY
EXAMPLE
/*
* Character Key Example
*/
#include "sc_base.h"
void main()
{
char ndx, character[9];
long recno;
scdinit(15);
if (scdnopen(&ndx,"CHAR.NDX") == SC_SUCCESS) {
date[8] = 0;
scdkfirst(ndx,character,&recno);
printf("%s %ld\n",character,recno);
scdnclose(ndx);
}
scdterm();
}
/*
* Date Key Example
*/
#include "sc_base.h"
void main()
{
char ndx;
double date;
long recno;
scdinit(15);
if (scdnopen(&ndx,"DATE.NDX") == SC_SUCCESS) {
date[8] = 0;
scdkfirst(ndx,&date,&recno);
printf("%lf %ld\n",date,recno);
scdnclose(ndx);
}
scdterm();
}
108
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdklast
USAGE
signed int scdklast(
signed char handle,
signed char *key,
signed long *recno );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scdklast will set the current key pointer to the
last logical key in the index and return the key
value "key" and data record number "recno"
associated with the new current key.
The user must ensure that the buffer used to
return the key is large enough to hold the entire
key. The maximum length of the key can be
determined via a call to scdninfo.
Note that numeric keys are returned as doubles,
and character keys are returned as strings.
SEE ALSO
scdninfo.
RETURN VALUE
SC_END successfully found the last key
SC_BADHNDL index file not open or bad handle
SC_EMPTY index file empty - no keys found
SC_SKFAIL seek failure
SC_RDFAIL read from index file failure
SC_NULLPARM parameter address null
109
CHAPTER 6, THE SOFTC DATABASE LIBRARY
EXAMPLE
/*
* Character Key Example
*/
#include "sc_base.h"
void main()
{
char ndx, character[9];
long recno;
scdinit(15);
if (scdnopen(&ndx,"CHAR.NDX") == SC_SUCCESS) {
date[8] = 0;
scdklast(ndx,character,&recno);
printf("%s %ld\n",character,recno);
scdnclose(ndx);
}
scdterm();
}
/*
* Numeric Key Example
*/
#include "sc_base.h"
void main()
{
char ndx;
double numeric;
long recno;
scdinit(15);
if (scdnopen(&ndx,"NUMERIC.NDX") == SC_SUCCESS) {
date[8] = 0;
scdklast(ndx,&numeric,&recno);
printf("%lf %ld\n",numeric,recno);
scdnclose(ndx);
}
scdterm();
}
110
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdkmake
USAGE
signed int scdkmake(
signed char datahandle,
signed char indexhandle,
void **key );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scdkmake will build an index key using the key
expression of the index file specified by
"indexhandle" and the data found in the output
buffer of the data file "datahandle". Memory space
for the "key" will be allocated and the address of
this block will be returned.
The key expression can consist of either the data
field name or one of five dBASE functions or a
combination thereof. Data field types of date,
numeric, or character are allowed. dBASE functions
dtoc, left, right, str, and substr are currently
supported by scdkmake.
Following is a brief description of the five
expression functions:
dtoc will convert data from a date field to an
ASCIIZ string of the format mm/dd/yy. Syntax is:
dtoc(field_name)
111
CHAPTER 6, THE SOFTC DATABASE LIBRARY
left will return the left portion of a character
field as an ASCIIZ string. The number of
characters returned is specified after the field
name. Syntax is:
left(field_name,number)
right will return the right portion of a character
field as an ASCIIZ string. The number of
characters returned is specified after the field
name. This is a count from the right side of the
field. Syntax is:
right(field_name,number)
str will convert a numeric field to an ASCIIZ
string. The total length of the string and the
number of decimal places are optional parameters.
The default string length is 10 and the number of
decimal places is 0. Syntax is:
str(field_name,length,decimal_places)
substr will return the middle portion of a
character field. The starting offset into the
field is a required parameter. The number of
characters to be used is an optional parameter
whose default value is the remainder of the field.
Syntax is:
substr(field_name,start,count)
An example of a more complex key expression:
right(dtoc(date),2)+left(dtoc(date,2)
This expression would cause scdkmake to create an
index key string consisting of the year and month
("yymm"). For example if date equals "2/13/89" the
resultant key would be "8902".
112
CHAPTER 6, THE SOFTC DATABASE LIBRARY
Note that for key expressions consisting of only
one data field scdkmake is probably an overkill.
You can easily generate these keys yourself. See
scdkdate for information on date string to key
translation. scdkmake is a fairly large module and
if not needed probably should not be used. This
function is best used when the key expression is
more complex.
Note that memory is allocated for the generated
key and it is the responsibility of the caller to
free this memory when finished.
SEE ALSO
scdncreate, scdkdate, scdkmakex.
RETURN VALUE
SC_SUCCESS key created
SC_BADHNDL index file not open or bad handle
SC_MEMERR memory allocation failure
SC_BADEXPR invalid key expression
SC_NULLPARM parameter address null
SC_BADFLDN invalid field name
EXAMPLE
#include "sc_base.h"
void main()
{
char ndx, dbf, char *key, date[9];
long recno;
scdinit(15);
if (scddopen(&dbf,"TEST.DBF") == SC_SUCCESS) {
if (scdnopen(&ndx,"TEST.NDX") == SC_SUCCESS) {
scdfput(dbf,0,&date);
scdrput(dbf,&recno,SC_ADD);
scdkmake(dbf,ndx,(void **) &key);
scdkadd(ndx,key,recno);
free(key); /* free memory allocated for key */
scdnclose(ndx);
}
scddclose(dbf);
}
scdterm();
}
113
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdkmakex
USAGE
signed int scdkmakex(
signed char datahandle,
signed char indexhandle,
void **key,
signed int buffer );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scdkmakex is an extended form of scdkmake which
enables the use of either I/O buffer. Which buffer
used is determined by "buffer": SC_INPUT - input
buffer, SC_OUTPUT - output buffer.
SEE ALSO
scdkmake
RETURN VALUE
SC_SUCCESS key created
SC_BADHNDL index file not open or bad handle
SC_MEMERR memory allocation failure
SC_BADEXPR invalid key expression
SC_NULLPARM parameter address null
SC_BADFLDN invalid field name
SC_BADCMD invalid I/O buffer selection
EXAMPLE
#include "sc_base.h"
void main()
{
char ndx, dbf, char *key, date[9];
114
CHAPTER 6, THE SOFTC DATABASE LIBRARY
long recno;
scdinit(15);
if (scddopen(&dbf,"TEST.DBF") == SC_SUCCESS) {
if (scdnopen(&ndx,"TEST.NDX") == SC_SUCCESS) {
scdfput(dbf,0,&date);
scdrput(dbf,&recno,SC_ADD);
scdkmakex(dbf,ndx,(void **) &key, SC_OUTPUT);
scdkadd(ndx,key,recno);
free(key); /* free memory allocated for key */
scdnclose(ndx);
}
scddclose(dbf);
}
scdterm();
}
115
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdknext
USAGE
signed int scdknext(
signed char handle,
signed char *key,
signed long *recno );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scdknext will increment the key pointer and return
the key value "key" and data record number "recno"
associated with the new current key.
If scdknext is called immediately after opening
the index file the first logical key will be
returned.
The user must ensure that the buffer used to
return the key is large enough to hold the entire
key. The maximum length of the key can be
determined via a call to scdninfo.
Note that numeric keys are returned as doubles,
and character keys are returned as strings.
SEE ALSO
scdninfo.
RETURN VALUE
SC_SUCCESS successfully returned "key" and
"recno"
SC_BADHNDL index file not open or bad handle
116
CHAPTER 6, THE SOFTC DATABASE LIBRARY
SC_END success but at end of index file
SC_RDFAIL index file read failure
SC_SKFAIL seek failure (bad record address or seek
failed)
SC_NULLPARM parameter address null
EXAMPLE
/*
* Character Key Example
*/
#include "sc_base.h"
void main()
{
char ndx, character[9];
long recno;
scdinit(15);
if (scdnopen(&ndx,"CHAR.NDX") == SC_SUCCESS) {
scdknext(ndx,character,&recno); /* return first key
*/
printf("%s %ld\n",character,recno);
scdnclose(ndx);
}
scdterm();
}
/*
* Numeric Key Example
*/
#include "sc_base.h"
void main()
{
char ndx;
double numeric;
long recno;
scdinit(15);
if (scdnopen(&ndx,"NUMERIC.NDX") == SC_SUCCESS) {
scdknext(ndx,&numeric,&recno); /* return first key */
printf("%lf %ld\n",numeric,recno);
scdnclose(ndx);
}
117
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdterm();
}
118
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdkprev
USAGE
signed int scdkprev(
signed char handle,
signed char *key,
signed long *recno );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scdkprev will decrement the key pointer and return
the key value "key" and data record number "recno"
associated with the new current key.
If scdkprev is called immediately after opening
the index file the last logical key will be
returned.
The user must ensure that the buffer used to
return the key is large enough to hold the entire
key. The maximum length of the key can be
determined via a call to scdninfo.
Note that numeric keys are returned as doubles,
and character keys are returned as strings.
SEE ALSO
scdninfo.
RETURN VALUE
SC_SUCCESS successfully returned "key" and
"recno"
SC_BADHNDL index file not open or bad handle
119
CHAPTER 6, THE SOFTC DATABASE LIBRARY
SC_END success but at end of index file
SC_RDFAIL index file read failure
SC_SKFAIL index file record seek failure
SC_NULLPARM parameter address null
EXAMPLE
/*
* Character Key Example
*/
#include "sc_base.h"
void main()
{
char ndx, character[9];
long recno;
scdinit(15);
if (scdnopen(&ndx,"CHAR.NDX") == SC_SUCCESS) {
scdkprev(ndx,character,&recno); /* get last key */
printf("%s %ld\n",character,recno);
scdnclose(ndx);
}
scdterm();
}
/*
* Date Key Example
*/
#include "sc_base.h"
void main()
{
char ndx;
double date;
long recno;
scdinit(15);
if (scdnopen(&ndx,"DATE.NDX") == SC_SUCCESS) {
scdkprev(ndx,&date,&recno); /* get last key */
printf("%lf %ld\n",date,recno);
scdnclose(ndx);
}
scdterm();
}
120
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdnclose
USAGE
signed int scdnclose(
signed char handle );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scdnclose closes an index file and frees all
allocated memory associated with index file.
RETURN VALUE
SC_SUCCESS index file closed
SC_CLOSFAIL file close failure
SC_BADHNDL index file not open or bad handle
EXAMPLE
#include "sc_base.h"
void main()
{
char ndx;
scdinit(15);
if (scdnopen(&ndx,"TEST.NDX") == SC_SUCCESS)
scdnclose(ndx);
scdterm();
}
121
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdncreate
USAGE
signed int scdncreate(
signed char *filename,
signed char keytype,
signed char *keyexpr,
signed char keylen );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scdncreate creates an index file. "keyexpr" will
be translated to all upper case when the index
file is created.
If "keytype" is 'c', then "keyexpr" must be an
ASCIIZ string consisting of one or more field
names from the data record. All fields included in
the expression must be of type 'c' or be
translated into type 'c'. No check is made to
verify this. "keyexpr" cannot be longer that 220
characters. "keylen" cannot exceed 100.
If "keytype" is 'n' or 'd', then "keyexpr" should
consist of only one data field. "keylen" will
automatically be set to 8 (numeric and date keys
are stored as doubles). For both date and numeric
keys "keytype" will be forced to 'n'.
NOTE: scdncreate will create a new index file even
if one had already existed.
NOTE: "keyexpr" is used by dBASE. "keyexpr" is NOT
checked for validity during the file creation
122
CHAPTER 6, THE SOFTC DATABASE LIBRARY
process. Currently only the scdkmake function uses
"keyexpr".
SEE ALSO
scdkmake.
RETURN VALUE
SC_SUCCESS index file created
SC_WRTFAIL disk write failure
SC_BADEXPR invalid keytype or bad keyexpr
SC_NOHNDL no DOS handles available
SC_NULLPARM parameter address null
SC_BADKEYT invalid key type
SC_KEYLEN invalid key length
SC_BADFNAME invalid filename
EXAMPLE
#include "sc_base.h"
void main()
{
scdinit(15);
scdncreate("TEST.NDX",'d',"date",8);
scdterm();
}
123
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdnexpr
USAGE
signed int scdnexpr(
signed char handle,
signed char *keyexpr );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scdnexpr gets the index key expression and returns
it as an ASCIIZ string into a user supplied buffer
"keyexpr". The user must ensure that the buffer is
large enough (the key expression length can be
determined via a call to scdninfo) to hold the
entire key expression.
A NULL byte will be appended to the end of the
expression string returned. If you are dynamically
allocating memory be sure to make the buffer large
enough.
SEE ALSO
scdninfo.
RETURN VALUE
SC_SUCCESS returned the key expression string
SC_BADHNDL index file not open or bad handle
SC_NULLPARM parameter address null
EXAMPLE
#include "sc_base.h"
void main()
124
CHAPTER 6, THE SOFTC DATABASE LIBRARY
{
char ndx, buffer[512];
scdinit(15);
if (scdnopen(&ndx,"TEST.NDX") == SC_SUCCESS) {
scdnexpr(ndx,buffer);
printf("key expression = %s",buffer);
scdnclose(ndx);
}
scdterm();
}
125
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdninfo
USAGE
signed int scdninfo(
signed char handle,
signed char *filename,
signed char *keytype,
signed char *keylen,
signed int *exprlen );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scdninfo gets the filename of the index file
associated with "handle", the index key type
"keytype", the maximum index key length "keylen",
and the length of the index key expression
"exprlen".
If you are using "exprlen" to dynamically allocate
memory to hold the key expression be sure to add
one to the length before allocation.
SEE ALSO
scdnopen.
RETURN VALUE
SC_SUCCESS returned index file information
SC_BADHNDL index file not open or bad handle
SC_NULLPARM parameter address null
EXAMPLE
#include <dir.h>
#include "sc_base.h"
126
CHAPTER 6, THE SOFTC DATABASE LIBRARY
void main()
{
char ndx, filename[MAXPATH], keytype, keylen, exprlen;
scdinit(15);
if (scdnopen(&ndx,"TEST.NDX") == SC_SUCCESS) {
scdninfo(ndx,filename,&keytype,&keylen,&exprlen);
printf("File name = %s\n",filename);
printf("Index key type = %c\n",keytype);
printf("Maximum key length = %d\n",keylen);
printf("Key expression length = %d\n",exprlen);
scdnclose(ndx);
}
scdterm();
}
127
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdnopen
USAGE
signed int scdnopen(
signed char *handle,
signed char *filename );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scdnopen opens an index file (.NDX). Memory will
be allocated for a file packet, I/O buffers, and
other miscellaneous structures for use internally
by the SoftC Database Library file manager. The
index file will be tested as much as possible to
insure that it is a legitimate dBASE index file.
The index expression will be translated to upper
case after being read from the index file.
RETURN VALUE
SC_SUCCESS index file opened
SC_MEMERR memory allocation failure
SC_NOFILE index file not found
SC_RDFAIL disk read failure
SC_SKFAIL disk seek failure
SC_NOHNDL no SoftC handles available
SC_BADFNAME invalid filename
SC_NULLPARM parameter address null
SC_KEYLEN invalid key length
SC_ITEMLEN invalid key item length
SC_BADROOT invalid root page number
SC_MAXKEYS bad maximum number of keys
SC_FILENGTH invalid file length
SC_BADKEYT invalid key type
128
CHAPTER 6, THE SOFTC DATABASE LIBRARY
EXAMPLE
#include "sc_base.h"
void main()
{
char ndx;
scdinit(15);
if (scdnopen(&ndx,"UNKNOWN.NDX") == SC_SUCCESS) {
scdnclose(ndx);
}
scdterm();
}
129
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdpinfo
USAGE
signed int scdpinfo(
signed char handle,
signed char *numpgs );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scdpinfo gets the maximum number of index pages
the library file manager can keep in memory and
returns it via "numpgs".
RETURN VALUE
SC_SUCCESS max number of pages allowed
returned
SC_BADHNDL index file not open or bad handle
SC_NULLPARM parameter address null
EXAMPLE
#include "sc_base.h"
void main()
{
char ndx, numpgs;
scdinit(15);
if (scdnopen(&ndx,"TEST.NDX") == SC_SUCCESS) {
scdpinfo(ndx,&numpgs) == SC_SUCCESS)
printf("Maximum number of pages = %d\n",numpgs);
scdnclose(ndx);
}
scdterm();
}
130
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdpnum
USAGE
signed int scdpnum(
signed char handle,
signed char *numpgs );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scdpnum sets the maximum number of index pages
"numpgs" the library file manager can keep in
memory. Memory for index pages will be freed or
allocated as appropriate.
RETURN VALUE
SC_SUCCESS new max number of pages allowed
returned
SC_BADHNDL index file was open or bad handle
SC_BADCMD invalid new number of pages requested
SC_NULLPARM parameter address null
EXAMPLE
#include "sc_base.h"
void main()
{
char ndx, numpgs = 5;
scdinit(15);
if (scdnopen(&ndx,"TEST.NDX") == SC_SUCCESS) {
scdpnum(ndx,&numpgs);
scdpinfo(ndx,&numpgs);
printf("New max = %d\n",numpgs);
scdnclose(ndx);
}
131
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdterm();
}
132
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdrclear
USAGE
signed int scdrclear(
signed char handle,
signed int buffer );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scdrclear clears a data I/O buffer. "buffer"
indicates which record buffer to clear.
"buffer" = clears this buffer
SC_INPUT input
SC_OUTPUT output
The selected buffer will be written with spaces ("
") NOT zeros (0).
RETURN VALUE
SC_SUCCESS buffer cleared
SC_BADHNDL data file not open or bad handle
SC_BADCMD invalid buffer
EXAMPLE
#include "sc_base.h"
void main()
{
char dbf, character[17] = "Hello World!";
scdinit(15);
if (scddopen(&dbf,"TEST.DBF") == SC_SUCCESS) {
133
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdfputs(dbf,0,"SoftC Database Library ");
scdrclear(dbf,SC_INPUT);
scdrcopy(dbf,SC_OUTPUT);
scdfgets(dbf,0,character);
printf("%s\n",character);
}
scdterm();
}
134
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdrcopy
USAGE
signed int scdrcopy(
signed char handle,
signed int buffer );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scdrcopy copies the contents of one I/O buffer to
the other. "buffer" indicates the direction of the
copy.
"buffer" = copies this way
SC_INPUT input to output
SC_OUTPUT output to input
RETURN VALUE
SC_SUCCESS buffer copied successfully
SC_BADHNDL data file not open or bad handle
SC_BADCMD invalid buffer
EXAMPLE
#include "sc_base.h"
void main()
{
char dbf, character[17] = "Hello World!";
scdinit(15);
if (scddopen(&dbf,"TEST.DBF") == SC_SUCCESS) {
scdfputs(dbf,0,"SoftC Database Library ");
scdrclear(dbf,SC_INPUT);
scdrcopy(dbf,SC_OUTPUT);
135
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdfgets(dbf,0,character);
printf("%s\n",character);
scddclose(dbf);
}
scdterm();
}
136
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdrdel
USAGE
signed int scdrdel(
signed char handle,
signed long recno );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scdrdel will flag a record specified by "recno" as
'deleted'. To maintain compatibility with dBASE
the data record cannot be reused, but it can be
'undeleted' by scdrundel.
SEE ALSO
scdrundel.
RETURN VALUE
SC_SUCCESS record marked 'deleted'
SC_BADHNDL data file not open or bad handle
SC_SKFAIL invalid data record number or disk seek
failure
SC_RDFAIL disk read failure
SC_WRTFAIL disk write failure
EXAMPLE
#include "sc_base.h"
void main()
{
char dbf;
scdinit(15);
if (scddopen(&dbf,"TEST.DBF") == SC_SUCCESS) {
137
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdrdel(dbf,1L);
scdrget(dbf,1L);
printf("%s\n",scemsg());
scddclose(dbf);
}
scdterm();
}
138
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdrget
USAGE
signed int scdrget(
signed char handle,
signed long recno );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scdrget will read the data record specified by
"recno" from the data file associated with
"handle" into the internal input buffer.
SEE ALSO
scdfget, scdfput, scdrput.
RETURN VALUE
SC_SUCCESS record read
SC_BADHNDL data file not open or bad handle
SC_SKFAIL invalid data record number or disk seek
failure
SC_RDFAIL disk read failure
SC_DELREC record read was marked 'deleted'
EXAMPLE
#include "sc_base.h"
void main()
{
char dbf, character[17] = "Hello",
logical = 'F', date[9] = "12/25/88";
double numeric = 150.00L;
unsigned long memo = 1L;
139
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdinit(15);
if (scddopen(&dbf,"TEST.DBF") == SC_SUCCESS) {
scdrget(dbf,1L);
scdfgets(dbf,0,character);
scdfgets(dbf,1,date);
scdfget(dbf,2,(void *) &logical);
scdfget(dbf,3,(void *) &memo);
scdfget(dbf,4,(void *) &numeric);
printf("%s %s %c %lu %lf\n",
character,date,logical,memo,numeric);
scddclose(dbf);
}
scdterm();
}
140
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdrinfo
USAGE
signed int scdrinfo(
signed char handle,
signed int *reclen,
signed char *numflds,
void **ibfr,
void **obfr );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scdrinfo gets the data record length "reclen", the
number of data fields per record "numflds", and
the addresses of the input "ibfr" and output
"obfr" buffers.
RETURN VALUE
SC_SUCCESS requested information returned
SC_BADHNDL data file not open or bad handle
SC_NULLPARM parameter address null
EXAMPLE
#include "sc_base.h"
void main()
{
char dbf, numflds;
short reclen;
void *ibfr, *obfr;
scdinit(15);
if (scddopen(&dbf,"TEST.DBF") == SC_SUCCESS) {
scdrinfo(dbf,&reclen,&numflds,&ibfr,&obfr);
printf("Record length = %d\n",reclen);
141
CHAPTER 6, THE SOFTC DATABASE LIBRARY
printf("Number of fields = %d\n",numflds);
printf("I/O buffers = %p %p\n",ibfr,obfr);
scddclose(dbf);
}
scdterm();
}
142
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdrput
USAGE
signed int scdrput(
signed char handle,
signed long *recno,
signed int howto );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scdrput will write the data record specified by
"recno" to the data file associated with "handle"
from the internal output buffer. "howto"
determines how the data record is to be written:
"howto" = action
SC_ADD append to end of file
SC_UPDATE update current record
If a record update is occurring the data record
number associated with the record in the input
buffer will be returned. An update will not be
performed if the input buffer is empty. Use
scdrget/scdrcopy to load a data record or scdfput
or scdfputs to fill the data record field by
field.
SEE ALSO
scdfput, scdfputs, scdrget, scdrcopy.
RETURN VALUE
SC_SUCCESS record written
SC_BADHNDL data file not open or bad handle
143
CHAPTER 6, THE SOFTC DATABASE LIBRARY
SC_SKFAIL invalid data record number or disk seek
failure
SC_WRTFAIL disk write failure
SC_BADCMD invalid record write command
SC_NULLPARM parameter address null
EXAMPLE
#include "sc_base.h"
void main()
{
char dbf, logical = 'T', date[9] = "19881225";
long recno;
double numeric = 20.0L;
unsigned long memo = 1L;
scdinit(15);
if (scddopen(&dbf,"TEST.DBF") == SC_SUCCESS) {
scdfputs(dbf,0,"SoftC Database Library ");
scdfput(dbf,1,(void *) date);
scdfput(dbf,2,(void *) &logical);
scdfput(dbf,3,(void *) &memo);
scdfput(dbf,4,(void *) &numeric);
scdrput(dbf,&recno,SC_ADD);
printf("Record number = %ld\n",recno);
scddclose(dbf);
}
scdterm();
}
144
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdrundel
USAGE
signed int scdrundel(
signed char handle,
signed long recno );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scdrundel will remove the 'deleted' flag from the
data record specified by "recno".
SEE ALSO
scdrdel.
RETURN VALUE
SC_SUCCESS record recovered
SC_BADHNDL data file not open or bad handle
SC_SKFAIL invalid data record number or disk seek
failure
SC_RDFAIL disk read failure
SC_WRTFAIL disk write failure
EXAMPLE
#include "sc_base.h"
void main()
{
char dbf;
long recno;
scdinit(15);
if (scddopen(&dbf,"TEST.DBF") == SC_SUCCESS) {
scdrundel(dbf,1L);
145
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdrget(dbf,1L);
printf("%s\n",scemsg());
scddclose(dbf);
}
scdterm();
}
146
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdtclose
USAGE
signed int scdtclose(
signed char handle );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scdtclose closes a memo file and frees all
allocated memory associated with memo file
"handle".
SEE ALSO
scdtopen.
RETURN VALUE
SC_SUCCESS memo file closed
SC_CLOSFAIL file close failure
SC_BADHNDL memo file not open or bad handle
EXAMPLE
#include "sc_base.h"
void main()
{
char dbt;
scdinit(15);
if (scdtopen(&dbt,"TEST.DBT") == SC_SUCCESS)
scdtclose(dbt);
scdterm();
}
147
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdtcreate
USAGE
signed int scdtcreate(
signed char *filename );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scdtcreate creates a memo file. This function will
create a new memo file even if one had already
existed.
RETURN VALUE
SC_SUCCESS memo file created
SC_WRTFAIL disk write failure
SC_BADFNAME invalid filename
SC_NOHNDL no DOS file handles available
SC_NULLPARM parameter address null
EXAMPLE
#include "sc_base.h"
void main()
{
scdinit(15);
scdtcreate("TEST.DBT");
scdterm();
}
148
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdterm
USAGE
signed int scdterm( void );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scdterm is called once at the end of the program.
Memory allocated by scdinit for internal control
structures will be freed. All files open will be
closed and any memory allocated for them will be
freed.
SEE ALSO
scdinit.
RETURN VALUE
SC_SUCCESS completed shutdown
EXAMPLE
#include "sc_base.h"
void main()
{
scdinit(15);
scdterm();
}
149
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdtinfo
USAGE
signed int scdtinfo(
signed char handle,
signed char *filename );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scdtinfo gets the name of the memo file associated
with "handle".
SEE ALSO
scdtopen.
RETURN VALUE
SC_SUCCESS file name returned
SC_BADHNDL memo file not open or bad handle
SC_NULLPARM parameter address null
EXAMPLE
#include "sc_base.h"
void main()
{
char dbt, filename[13];
scdinit(15);
if (scdtopen(&dbt,"TEST.DBT") == SC_SUCCESS) {
scdtinfo(dbt,filename);
printf("%s",filename);
scdtclose(dbt);
}
scdterm();
150
CHAPTER 6, THE SOFTC DATABASE LIBRARY
}
151
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdtopen
USAGE
signed int scdtopen(
signed char *handle,
signed char *filename );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scdtopen opens a memo file. Memory will be
allocated for a file packet and I/O buffers for
use internally by the library file manager. The
memo file will be tested as much as possible to
insure that it is a legitimate dBASEIII+ memo
file.
RETURN VALUE
SC_SUCCESS memo file opened
SC_NULLPARM parameter address null
SC_MEMERR memory allocation failure
SC_NOFILE memo file not found
SC_RDFAIL disk read failure
SC_NOHNDL no SoftC file handles available
SC_BADFNAME invalid filename
SC_NODBT file was not in memo format
EXAMPLE
#include "sc_base.h"
void main()
{
char dbt;
scdinit(15);
if (scdtopen(&dbt,"TEST.DBT") == SC_SUCCESS)
152
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdtclose(dbt);
scdterm();
}
153
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scdvers
USAGE
signed char *scdvers( void );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scdvers returns a pointer to the SoftC Database
Library revision ASCIIZ string.
RETURN VALUE
scdvers returns the library revision.
EXAMPLE
#include "sc_base.h"
void main()
{
scdinit(15);
printf("SoftC Database Library Revision %s",scdvers());
scdterm();
}
154
CHAPTER 6, THE SOFTC DATABASE LIBRARY
sceclr
USAGE
void sceclr( void );
PROTOTYPE IN
sc_base.h
DESCRIPTION
sceclr will clear the SoftC Database Library error
flag (sc_code).
SEE ALSO
scemsg.
RETURN VALUE
None.
EXAMPLE
#include "sc_base.h"
void main()
{
scdinit(15);
if ((scddopen(&dbf,"Customer.dbf") == SC_SUCCESS) &&
(scdnopen(&ndx1,"custcode.ndx") == SC_SUCCESS))
scdnopen(&ndx2,"custname.ndx");
if (sc_code < SC_SUCCESS) {
select("Data files missing. Create new files
(Y/N)","YN",&ch);
if (ch == 'Y') {
sceclr();
scddcreate("Customer.dbf",12,fields);
scdncreate("CUSTCODE.NDX",'N',"CODE",8);
scdncreate("CUSTNAME.NDX",'c',"lastname",25);
if ((scddopen(&dbf,"Customer.dbf") == SC_SUCCESS) &&
155
CHAPTER 6, THE SOFTC DATABASE LIBRARY
(scdnopen(&ndx1,"custcode.ndx") == SC_SUCCESS))
scdnopen(&ndx2,"custname.ndx");
if (sc_code < SC_SUCCESS)
exit(1);
}
else
exit(1);
}
sceclr();
scdterm();
}
156
CHAPTER 6, THE SOFTC DATABASE LIBRARY
scemsg
USAGE
signed char *scemsg( void );
PROTOTYPE IN
sc_base.h
DESCRIPTION
scemsg returns a pointer to the SoftC Database
Library error or warning message which corresponds
to the code found in sc_code.
SEE ALSO
sceclr.
RETURN VALUE
scemsg returns the message text.
EXAMPLE
#include "sc_base.h"
void main()
{
char dbf;
scdinit(15);
if (scdopen(&dbf,"TEST.DBF") != SC_SUCCESS)
printf("%s",scemsg());
else
printf("File opened O.K.");
scdterm();
}
157
Appendix A
Result Codes and Messages
Warning Codes and Messages
SC_DELREC 1 "WARNING - record read is marked deleted"
The data file record just read was flagged as "inactive" or
"deleted". dBASE retains "deleted" records until the data
file is packed.
SC_EMPTY 2 "WARNING - file is empty"
You have attempted to read from an index file which has no
keys (is empty).
SC_END 3 "WARNING - no more keys"
The current key pointer is located at the physical end of
the index file, either at the first key or at the last key.
The actual position depends upon the function called.
SC_NOFIND 4 "WARNING - could not find key in index file"
The index key supplied to the function could not be found in
the index file. Make sure that the index key is being built
properly.
SC_FLDTRUNC 5 "WARNING - data field truncated"
The length of the data supplied is larger than the space
allocated for the field in the data file record. This
usually occurs only with character type fields.
SC_FLDROUND 6 "WARNING - numeric field rounded"
Numeric data is not stored in the data record in floating
point format, rather it is converted to ASCII and then
stored complete with decimal point. If the numeric value
desired to be written is more precise than space in the
158
APPENDIX A, RESULT CODES AND MESSAGES
field permits the data will be rounded and this warning
returned.
SC_FILENGTH 7 "WARNING - file length is incorrect"
After data, index, or memo files are opened, the calculated
file length is compared to the actual length. If they do not
agree this code is returned. This warning will occur most
frequently with data files.
Error Codes and Messages
SC_WRTFAIL -1 "ERROR - file write failure"
This indicates a file write error of some sort. The disk may
be full, the floppy drive door may be open, ... In this case
a check of the compiler global variable errno should be made
in order to determine the cause of the failure.
SC_RDFAIL -2 "ERROR - file read failure"
This indicates a file read error of some sort. The global
variable errno should be checked to help isolate the
failure.
SC_MEMERR -3 "ERROR - memory allocation error"
An attempt to allocate memory by the file manager has
failed. This failure could be caused by many things: not
enough memory available, memory threads corrupted, using a
null pointer, ... Check your code to ensure that you do not
have a problem in this area. You may have to go to a larger
data model.
SC_SKFAIL -4 "ERROR - file pointer reposition failed"
This error is returned under two circumstances: actual seek
failed or an attempt was made to seek beyond the end of the
file in a function intending to read after seek. In the
first case a check of errno may prove to be helpful. In the
second case you should verify the record number (for either
data, index, or memo files) being requested is legitimate.
159
APPENDIX A, RESULT CODES AND MESSAGES
SC_NOFILE -5 "ERROR - file not found"
You have attempted to open a data, index, or memo file which
cannot be found. If you are certain the file exists, check
the path specification.
SC_FILBAD -6 "ERROR - file corrupted"
The file manager has noticed something seriously wrong with
the index file. Close and reopen the file, it may still be
good. Otherwise you will have to rebuild the index file.
SC_BADEXPR -7 "ERROR - bad user specified key
expression"
This indicates an error either with the length or the
contents of the expression. The length can be no larger than
220 characters. See scdkmake for more information on valid
expression content.
SC_NOHNDL -8 "ERROR - no handles available"
Either DOS or the file manager has no more unused file
handles. Each DOS application is allowed to have a maximum
of twenty files open (up to the total defined by "FILES=" in
"CONFIG.SYS"). Five of these files are reserved for console,
printer, etc. which leaves only fifteen available for you.
scdinit can be used to specify the maximum number of SoftC
Database Library files which can be open simultaneously.
SC_NOPGS -9 "ERROR - no index pages loaded"
This is an internal file manager error which should never
occur. Contact SoftC, Ltd. if you get this error.
SC_BADPG -10 "ERROR - index page was not loaded"
This is an internal file manager error which should never
occur. Contact SoftC, Ltd. if you get this error.
SC_CLOSFAIL -11 "ERROR - file close failure"
This indicates that DOS could not properly close the file.
Check errno for help in isolating further.
160
APPENDIX A, RESULT CODES AND MESSAGES
SC_BADCMD -12 "ERROR - invalid command"
This error is a general purpose indicator. It means that the
I/O buffer selected, date string translation format, data
file record write type, or maximum number of resident index
pages was invalid depending upon the function executed.
SC_BADHNDL -13 "ERROR - invalid handle number"
The file handle does not match the function required file
type or there is no file open for that handle. For example
this will occur when using an index file handle with a data
file function.
SC_BADFNAME -14 "ERROR - invalid filename"
The length of the file name was zero or the file name was
invalid in some other way. The file manager expects file
names to be complete with an extension. File paths are
optional.
SC_BADDATE -15 "ERROR - invalid date"
The year, month, and/or day was invalid. Verify the date is
correct.
SC_BADTIME -16 "ERROR - invalid time"
The hour, minute, and/or second was invalid. Verify the time
is correct.
SC_NODBT -17 "ERROR - file not in .DBT format"
The memo file length was too short. This file cannot be
used.
SC_DBFVERS -18 "ERROR - invalid dBASE version"
The dBASE version number in the data file header was
unsupported. Only dBASEIII, dBASEIII+, and dBASEIV versions
are valid. This file cannot be used.
161
APPENDIX A, RESULT CODES AND MESSAGES
SC_DBFHLEN -19 "ERROR - file header length error"
The length of the dBASE header was invalid. The length of
the header must be divisible by 32 with a remainder of
either 0 or 1. This file cannot be used.
SC_DBFDATE -20 "ERROR - last file change date in error"
The data file header last modified date was invalid. This
file cannot be used.
SC_NULLPARM -21 "ERROR - parameter address null"
The address of a parameter is NULL. Check the parameters on
the call to ensure they are correct.
SC_BADKEYT -22 "ERROR - invalid key type"
Only index key types of character and numeric (includes
dates) are supported. Make sure the key type is of 'C', 'D',
or 'N'. All others are invalid.
SC_KEYLEN -23 "ERROR - invalid key length"
The character key maximum length definition exceeds 100
characters. This error does not occur for numeric (or date)
keys.
SC_ITEMLEN -24 "ERROR - item length incorrect"
The file manager index key item length not agree with the
value read from the index file. This file cannot be used.
SC_BADROOT -25 "ERROR - invalid root page"
The index page number for the top of the Btree does not
exist in the index file. This file cannot be used.
SC_MAXKEYS -26 "ERROR - bad maximum number of keys per
page"
The file manager maximum number of index keys per index page
does not agree with the value read from the index file. This
file cannot be used.
162
APPENDIX A, RESULT CODES AND MESSAGES
SC_FLDCNT -27 "ERROR - invalid number of fields"
A data file record can consist of a maximum of 128
individual fields.
SC_BADFLDN -28 "ERROR - field name invalid"
The field name length cannot exceed ten characters not
including the null bye.
SC_FLDLEN -29 "ERROR - bad field length"
Character fields cannot be longer than 254 bytes. dBASE III
numeric fields cannot be longer than 19 bytes. dBASE IV
numeric and float fields cannot be longer than 20 bytes.
This error will not occur for the other field types.
SC_DECPL -30 "ERROR - decimal places parameter invalid"
The decimal places definition portion of the field
description cannot be less than 0 nor can it be greater than
the field length minus two.
SC_BADFLDT -31 "ERROR - invalid field type"
Only character ('C'), date ('D'), logical ('L'), memo ('M'),
and numeric ('N') are allowed in dBASE III files.
Additionally, dBASE IV supports a floating point ('F') field
type.
SC_RECLEN -32 "ERROR - invalid record length"
The record length cannot exceed 4000 bytes. Check your field
lengths and make sure that they total 4000 or less.
SC_BADDATA -33 "ERROR - bad data"
The data you requested to be written into a data field was
invalid. For example a pointer to a floating point variable
was passed for a character field. Ensure the data type
passed matches the field definition.
163
APPENDIX A, RESULT CODES AND MESSAGES
SC_LINELEN -34 "ERROR - memo soft line length invalid"
Valid values for line lengths are 0, and between 10 and 132.
The line length parameter is used when the file manager is
inserting soft carriage returns in memo text as it is
written to the memo file.
SC_MDXFLAG -35 "ERROR - MDX flag in DBF file invalid"
The value found in byte twenty eight (28) of the dBASEIV
data file is not valid. Only values of zero (0) and one (1)
are currently supported. This may indicate a corrupted file.
Other Messages
"Unknown error or warning code"
This message is returned by scemsg if it cannot find a
message which corresponds to the value found in sc_code. The
function scemsg may be old or otherwise incompatible with
the value found in sc_code.
164
Appendix B
Address List Program (DEMO1.C)
The Address List Program is a simple program which will
create a database (CUSTOMER.DBF) and two index files. The
database record contains the following fields:
field name type length description
__________________________________________
CODE N 10.0 customer code
DATE D 8 date added to file
FIRSTNAME C 15 first name
LASTNAME C 25 last name
COMPANY C 40 company name
ADDRESS C 30 street address, po box, etc
CITY C 20 city
STATE C 2 state
ZIPCODE C 5 5 digit zip code
AREACODE C 3 telephone area code
TELEPHONE C 8 telephone number
EXTENSION C 4 telephone extension
The index files created are: CUSTCODE.NDX (customer code),
and CUSTNAME.NDX (customer last name).
The program has two main functions: Update/Add new addresses
and List contents of database. It also supports a "Quit"
command.
The Update function enables the user to either add a new or
find an existing record. The Add subfunction displays a data
entry screen and then the user steps through the fields
filling the blanks as required (use Control Z to end Add
mode). The Find subfunction allows the user to select what
the search type will be: CODE or LASTNAME. Once the data to
be searched for has been entered, the user will be allowed
to scroll forward and backward through the data. After the
data record has been found, the user is allowed to edit or
delete the data record (and keys).
165
APPENDIX B, ADDRESS LIST DEMO PROGRAM
The List function allows the user to select where data will
be displayed (Printer/Screen) and how to sort the data
(Code/Name/Unsorted). The "CODE", "LASTNAME", and "COMPANY"
fields of each data record are displayed.
Seventeen lines of data are output to the screen as a page.
The user is then prompted to continue the display or abort.
Data sent to the printer is continuous with no headings or
page numbers.
The program as it stands is barely useable as an address
list manager but its real value is in the demonstration of
certain library functions. However, it could form the basis
of a full featured address list manager, or ...
166
Appendix C
Diskette TOC Demo Program
The Diskette TOC Program is a simple program which will
create a database (TOC.DBF) and three index files. The
database record contains the following fields:
field name type length description
__________________________________________
NAME C 12 file name
LENGTH N 10.0 file size in bytes
DATE D 8 file creation date
TIME C 8 file creation time
ATTRIBUTE C 3 file attribute (READ ONLY, HIDDEN)
The index files created are: TOCNAME.NDX (file name),
TOCLNGTH.NDX (file length), and TOCDATE.NDX (file creation
date and time).
The program uses the DOS functions "findfirst" and
"findnext" to step through the files in the directory. It
reformats the compressed file date ("mm/dd/yy") and time
("hh:mm:ss") and places the resultant data into the output
buffer. After all fields have been entered it will append a
record to the end of the database and add keys for each file
found.
The program only works on the current directory. It does not
support any command line arguments, although it would be
easy for the user to add such support. Very little error
checking is performed.
The program as it stands has value only in the demonstration
of certain library functions. However, it could form the
basis of a diskette cataloger, or ...
167
Index
sccds2n 17, 27, 34
Data sccdvalid 18, 24, 27, 36
field sccdxlat 17, 24, 37
array 52, 55, 78 sccleap 18, 39, 40
read sccleapi 18, 39, 40
memo 72, 74 sccmonth 17, 23, 41
strings 68, 70 scctdiff 18, 43
values 66, 76 scctn2s 18, 43, 45, 47
write sccts2n 18, 45, 47
memo 88, 90 scctvalid 18, 43, 45, 49
strings 84, 86 scddclose 12, 50
values 82, 92 scddcreate 12, 13, 52,
file 56
close 50 scddcreatex 53, 55
create 52, 55 scddinfo 12, 58, 60
I/O buffer clear 133 scddopen 12, 50, 58, 60,
I/O buffer copy 135 63
information 58 scddopenx 60, 62
number of records 65 scddsize 12, 65
open 60, 62 scdfget 14, 66, 68, 72,
record 76, 77, 82, 84, 86,
delete 137 92, 139
read 139 scdfgets 14, 67, 68, 70,
recover 145 76, 84, 86, 92, 93
write 143 scdfgetsx 14, 68, 70, 77
scdfgett 15, 66, 67, 72,
Date 74, 76, 88
calculate scdfgettx 15, 66, 67,
days per month 29, 31 74, 76
difference 24 scdfgetx 14, 67, 70, 76
test scdfinfo 14, 66, 67, 68,
leap year 39, 40 70, 77, 78
valid 36 scdfnam2no 14, 80
translate scdfput 14, 15, 67, 77,
string format 37 82, 84, 86, 88, 92,
to integers 34 93, 139, 143
to long 33 scdfputs 14, 68, 70, 82,
to string 84, 86, 92, 93, 143
day of week 23 scdfputsx 84, 86
integers 27 scdfputt 15, 72, 88, 90
long 26 scdfputtx 15, 88, 90
month 41 scdfputx 14, 82, 92
scdinit 3, 7, 19, 94,
Functions 149, 160
sccday 17, 23, 41 scdkadd 16, 96, 103
sccddiff 18, 24 scdkcur 16, 98
sccdl2s 17, 26 scdkdate 16, 96, 100,
sccdn2s 17, 24, 27, 34 101, 113
sccdperm 18, 29, 31 scdkdatex 16
sccdpermi 18, 29, 31 scdkdel 16, 103
sccds2l 17, 26, 33 scdkfind 16, 98, 105
168
INDEX
scdkfirst 16, 98, 107 close 121
scdklast 16, 98, 109 create 122
scdkmake 16, 96, 111, open 128
114, 123, 160 key
scdkmakex 16, 113, 114 add 96
scdknext 16, 98, 116 build 100, 101, 111,
scdkprev 16, 98, 119 114
scdnclose 15, 121 delete 103
scdncreate 15, 113, 122 get first 107
scdnexpr 15, 124 get last 109
scdninfo 15, 98, 105, read next 116
106, 107, 109, 116, read previous 119
119, 124, 126 search 105
scdnopen 15, 126, 128 page count
scdpinfo 16, 130 retrieve 130
scdpnum 16, 131 set 131
scdrclear 13, 133
scdrcopy 13, 135, 143 Initialization 94
scdrdel 13, 137, 145
scdrget 13, 67, 68, 70, Library version 154
77, 139, 143
scdrinfo 13, 78, 141 Memo file
scdrput 13, 139, 143 close 147
scdrundel 13, 137, 145 create 148
scdtclose 15, 147 open 152
scdtcreate 15, 148 read 72, 74
scdterm 7, 12, 19, 94, write 88, 90
149
scdtinfo 15, 150 Return codes
scdtopen 14, 147, 150, clear 155
152 defined 19, 158
scdvers 19, 154 errors
sceclr 20, 155, 157 SC_BADCMD 37, 71, 74,
scemsg 19, 155, 157, 164 77, 87, 93, 114,
131, 133, 135, 144,
Global variables 161
sc_code 19, 20, 22, 155, SC_BADDATA 83, 84, 87,
157, 164 93, 163
sc_softlen 15, 88 SC_BADDATE 23, 24, 26,
27, 29, 31, 33, 34,
Index 36, 37, 39, 40, 41,
expression 67, 68, 71, 77, 83,
defined 111, 122 84, 86, 93, 100,
functions 101, 161
dtoc 16, 111 SC_BADEXPR 113, 114,
left 16, 111, 112 123, 160
right 16, 111, 112 SC_BADFLDN 53, 57, 61,
str 16, 111, 112 63, 80, 113, 114,
substr 16, 111, 112 163
read 124 SC_BADFLDT 53, 56, 61,
file 63, 163
169
INDEX
SC_BADFNAME 53, 56, SC_NULLPARM 23, 24,
60, 63, 123, 128, 26, 27, 29, 31, 33,
148, 152, 161 34, 36, 37, 39, 40,
SC_BADHNDL 50, 58, 65, 41, 43, 45, 47, 49,
67, 68, 70, 72, 74, 53, 57, 58, 60, 63,
77, 79, 80, 83, 84, 65, 67, 68, 71, 72,
86, 88, 90, 93, 94, 74, 77, 79, 80, 83,
96, 98, 103, 106, 84, 86, 88, 90, 93,
107, 109, 113, 114, 96, 99, 100, 101,
116, 119, 121, 124, 103, 106, 107, 109,
126, 130, 131, 133, 113, 114, 117, 120,
135, 137, 139, 141, 123, 124, 126, 128,
143, 145, 147, 150, 130, 131, 141, 144,
161 148, 150, 152, 162
SC_BADKEYT 123, 128, SC_RDFAIL 60, 63, 72,
162 74, 96, 98, 103,
SC_BADPG 160 106, 107, 109, 117,
SC_BADROOT 128, 162 120, 128, 137, 139,
SC_BADTIME 43, 45, 47, 145, 152, 159
49, 161 SC_RECLEN 53, 57, 61,
SC_CLOSFAIL 50, 121, 63, 163
147, 160 SC_SKFAIL 50, 60, 63,
SC_DBFDATE 60, 63, 162 72, 74, 88, 90, 96,
SC_DBFHLEN 60, 63, 162 98, 103, 106, 107,
SC_DBFVERS 57, 60, 63, 109, 117, 120, 128,
161 137, 139, 144, 145,
SC_DECPL 53, 57, 163 159
SC_FILBAD 72, 74, 103, SC_WRTFAIL 50, 53, 56,
160 96, 103, 123, 137,
SC_FLDCNT 53, 56, 67, 144, 145, 148, 159
68, 71, 77, 83, 84, message translate 157
87, 93, 163 warnings
SC_FLDLEN 53, 57, 72, SC_DELREC 139, 158
74, 163 SC_EMPTY 103, 106,
SC_ITEMLEN 128, 162 107, 109, 158
SC_KEYLEN 123, 128, SC_END 98, 107, 109,
162 117, 120, 158
SC_LINELEN 88, 90, 164 SC_FILENGTH 61, 63,
SC_MAXKEYS 128, 162 128, 159
SC_MDXFLAG 61, 63, 164 SC_FLDROUND 83, 85,
SC_MEMERR 60, 63, 72, 87, 93, 158
74, 94, 96, 113, SC_FLDTRUNC 83, 84,
114, 128, 152, 159 87, 93, 158
SC_NODBT 152, 161 SC_NOFIND 103, 106,
SC_NOFILE 60, 63, 128, 158
152, 160
SC_NOHNDL 53, 57, 60, SC_2ASCII 37
63, 123, 128, 148,
152, 160 SC_2ASCIIL 37
SC_NOPGS 160
SC_2DBASE 37
170
INDEX
SC_ADD 143
SC_ASCII 101
SC_CRDELETE 74
SC_CRUNCHNG 74
SC_DB3 56
SC_DB4 56
SC_DBASE 101
SC_DBFINFO 58, 62
SC_EXACT 105
SC_FIELD 52, 55, 78
SC_FIRST 105, 106
SC_INPUT 70, 76, 86, 92,
114, 133, 135
SC_OUTPUT 70, 76, 86, 92,
114, 133, 135
SC_UPDATE 143
Termination 149
Time
calculation 43
test 49
translation 45, 47
171